2014-09-23 125 views
2

当使用铁路路由器更改为不同的模板(页面)时,是否会自动取消订阅不再需要的集合?下面的情形说明问题铁路路由器流星自动退订?

  1. 第一页上,我们称之为Meteor.subscribe(文件ID)
  2. 铁路由器更改为2
  3. 页第2页上,我们称之为Meteor.subscribe(文件,ID2) ,第1步自动取消订阅?
+0

是,流星会自动退订从订阅的反应计算了进去(这是典型的'铁的情况:路由器'),因此创建类似于订阅管理器的东西可以防止这种行为,如果你需要的话。 https://meteorhacks.com/subscriptions-manager-is-here.html – saimeunt 2014-09-23 12:53:06

回答

1

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

铁路由器/流星可以实现这个要求: 如果使用Deps.autorun反应计算中调用Meteor.subscribe,例如,认购将自动当计算取消无效或停止;

如果你希望缓存一些认购的,看到这个优秀的包装: 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 
    }); 
0

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