流星订阅会覆盖旧订阅吗?

编程入门 行业动态 更新时间:2024-10-27 12:34:30
本文介绍了流星订阅会覆盖旧订阅吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道流星订阅调用是否会覆盖同一集合的先前订阅?

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.

更多推荐

流星订阅会覆盖旧订阅吗?

本文发布于:2023-08-01 08:47:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1266979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流星

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!