Meteor.publish: 发布依赖于其他集合的集合 [英] Meteor.publish: publish collection which depends on other collection
问题描述
我有一个发布功能如下:
Meteor.publish('tasks', function (name) {var project = Projects.findOne({name: name});返回 Tasks.find({projectId: project._id});});
现在假设在某些时候对 Projects 进行了更改,结果上面的 Projects.findOne
返回一个不同的项目,因此 Tasks.find 将返回其他任务.但是,对项目所做的更改不会重新发布任务
我使用了reactivePublish,但结果是这个包有问题(而且也没有任何单元测试).那么,是否有一种简单的方法可以在项目更改时重新发布此发布功能?
概述
在撰写本文时,反应式连接是一个未解决的问题.如需完整概览,请参阅 Reactive Joins In Meteor.
建议
我强烈建议不要直接使用observeChanges.很难做到正确,而且很容易发生内存泄漏.如果您不相信我,请观看 这个视频在 EventedMind 上.它会让你的眼睛流血.
有几个基于包的解决方案来解决这个问题.流星指南 推荐 publish-composite.
如果您发现使用基于包的解决方案的想法不可接受,请仔细查看 Reactive Joins In Meteor.它很干净,但需要用户更多的等待.如果您更喜欢在模板级别激活订阅,请参阅我在 模板连接 上的帖子.>
I have a publish function as follows:
Meteor.publish('tasks', function (name) {
var project = Projects.findOne({name: name});
return Tasks.find({projectId: project._id});
});
Now assume that at some point changes are made to Projects with the result that the above Projects.findOne
returns a different project and so the Tasks.find will return other tasks.
However the changes made to Projects doesn't republish the tasks
I've used reactivePublish, but it turns out the package has issues (and also does not have any unit tests). So, is there an easy way to make this publish function re-publish when project changes ?
Overview
As of this writing, reactive joins are an unsolved problem. For a complete overview see Reactive Joins In Meteor.
Recommendations
I strongly recommend against using observeChanges directly. It's incredibly hard to get right, and easy to develop a memory leak. If you don't believe me, watch this video on EventedMind. It will make your eyes bleed.
There are several package-based solutions to this problem. The meteor guide recommends publish-composite.
If you find the idea of using a package-based solution to be unacceptable, have a close look at the Joining On The Client section from Reactive Joins In Meteor. It's clean but requires more waiting on the user's part. Also see my post on template joins if you prefer to active your subscriptions at the template level.
这篇关于Meteor.publish: 发布依赖于其他集合的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!