铁路由器流星自动退订? [英] Iron router meteor auto unsubscribe?

查看:39
本文介绍了铁路由器流星自动退订?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Iron Router更改为不同的模板(页面)时,它会自动取消订阅不再需要的收藏吗?下面的场景说明了问题

When using iron router to change to different template(pages), does it auto unsubscribe collection that no longer required ? Below scenario explain the question

  1. 在第1页上,我们称为Meteor.subscribe(document,id)
  2. 铁路由器更改为第2页
  3. 在第2页上,我们称为Meteor.subscribe(document,id2),步骤1是否自动取消订阅?

推荐答案

查看此处: https://github.com/EventedMind/iron-router/issues/265

铁路由器/流星为您做到这一点: 如果您在反应式计算中调用Meteor.subscribe,例如使用Deps.autorun,则在计算无效或停止时,该订阅将自动取消;

Iron Router/Meteor does this for you: If you call Meteor.subscribe within a reactive computation, for example using Deps.autorun, the subscription will automatically be cancelled when the computation is invalidated or stopped;

如果您希望缓存某些订阅,请参阅以下优秀软件包: https://meteorhacks.com/subscription-manager-for-iron-router.html

If you wish to cache some of the subscription, see this excellent package: 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
  });

这篇关于铁路由器流星自动退订?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆