【问题标题】:Iron router meteor auto unsubscribe?铁路由器流星自动退订?
【发布时间】:2014-09-23 20:57:28
【问题描述】:

当使用 Iron 路由器更改为不同的模板(页面)时,它是否会自动取消订阅不再需要的集合?下面的场景解释了这个问题

  1. 在第 1 页,我们调用 Meteor.subscribe(document, id)
  2. 铁路由器更改到第 2 页
  3. 在第 2 页,我们调用 Meteor.subscribe(document,id2) ,第 1 步会自动取消订阅吗?

【问题讨论】:

  • 是的,Meteor 会自动取消订阅在响应式计算中运行的订阅(这通常是 iron:router 中的情况),因此如果您需要,可以从流星黑客创建订阅管理器之类的东西,以防止这种行为. meteorhacks.com/subscriptions-manager-is-here.html

标签: meteor iron-router


【解决方案1】:

请看这里: https://github.com/EventedMind/iron-router/issues/265

Iron Router/Meteor 会为您执行以下操作: 如果你在响应式计算中调用 Meteor.subscribe,例如使用 Deps.autorun,当计算失效或停止时订阅将自动取消;

如果您想缓存一些订阅,请查看这个优秀的包: https://meteorhacks.com/subscription-manager-for-iron-router.html

this.route('postPage', {
    path: '/post/:_id',
    template: 'postPage',
    waitOn: function() {
      return Meteor.subscribe('post', this.params._id);
    },
    cache: 5, //cache 5 blog posts
    expire: 3 //expire them if inactive for 3 minutes
  });

【讨论】:

    【解决方案2】:

    如果您在路由的waitOn 函数中将句柄(或包含该句柄的数组)返回给订阅,则 Iron 路由器将为您取消订阅。

    【讨论】:

      猜你喜欢
      • 2014-09-03
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      相关资源
      最近更新 更多