流星订阅会覆盖旧订阅吗? [英] Does meteor subscribe overwrite old subscriptions?
问题描述
我想知道流星订阅调用是否会覆盖同一集合的先前订阅?
I was wondering if a meteor subscribe call overwrites previous subscriptions for the same collection?
例如如果我有分页并使用以下内容:
E.g. If I have pagination and use something like:
Meteor.subscribe('tasks',start,count);
Meteor.subscribe('tasks',start,count);
并调用:Meteor.subscribe('tasks',0,10);
and call: Meteor.subscribe('tasks',0,10);
然后前进到下一个订阅的页面
and then advance to the next page which subscribes to
Meteor.subscribe('tasks',10,10);
Meteor.subscribe('tasks',10,10);
...meteor 是将前 10 个结果保留在内存中还是删除旧内容?
... does meteor keep the first 10 results in memory or does it remove the old content?
我的最终目标是为用户提供手动订阅整个文档供以后离线使用的选项,我担心这种做法会干扰我在线使用的动态订阅.
My ultimate goal is to provide the user with options to manually subscribe to entire documents for later offline use and I am worried that this practice would interfere with my dynamic subscriptions for online use.
推荐答案
使用 Meteor.subscribe
开始订阅后,它将保持活动状态,直到手动停止或用户断开连接(关闭浏览器等).
Once you start a subscription with Meteor.subscribe
, it will remain active until it's manually stopped or the user disconnects (closes the browser, etc.).
因此,对您的问题的简短回答是:不,订阅将全部处于活动状态,任何重复的文档都将合并.
So the short answer to your question is: no, the subscriptions will all be active and any duplicate documents will be merged.
然而,这可能不是您想要的,因为除非您清理订阅,否则它们将继续存在.动态修改订阅参数的常见解决方案是使用 autorun
.这是一个模板级 autorun
的示例,我们根据一对会话变量订阅 tasks
:
This may not be what you want, however, because unless you clean up the subscriptions they will remain on. A common solution to dynamically modifying a subscription's parameters is to use an autorun
. Here's an example of a template-level autorun
where we subscribe for tasks
based on a pair of session variables:
Template.tasks.created = function () {
var self = this;
this.autorun(function () {
var start = Session.get('paginationStart');
var end = Session.get('paginationEnd');
self.subscribe('tasks', start, end);
});
};
autorun
将根据其反应性输入智能地启动和停止之前的订阅.
The autorun
will intelligently start and stop the previous subscription based on its reactive inputs.
有关meteor 分页的更多详细信息,我建议阅读这篇文章一>.
For more details on pagination in meteor, I'd recommend reading this post.
这篇关于流星订阅会覆盖旧订阅吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!