Meteor.publish:发布取决于其他集合的集合 [英] Meteor.publish: publish collection which depends on other collection

查看:156
本文介绍了Meteor.publish:发布取决于其他集合的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发布函数如下:

I have a publish function as follows:

Meteor.publish('tasks', function (name) {
    var project = Projects.findOne({name: name});

    return Tasks.find({projectId: project._id});
});

现在假设在某些时候对Projects进行了更改,结果是上面的 Projects.findOne 返回一个不同的项目,因此Tasks.find将返回其他任务。
但是对项目所做的更改不会重新发布任务

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

我已经使用了reactivePublish,但事实证明有问题(也没有任何单元测试)。那么,是否有一种简单的方法可以在项目更改时重新发布此发布函数?

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 ?

推荐答案

概述



在撰写本文时,反应性连接是一个未解决的问题。有关完整概述,请参阅 Reactive Join in Meteor

强烈建议不要使用 observeChanges 直接。要做到这一点非常困难,并且很容易产生内存泄漏。如果您不相信我,请观看这个视频关于EventedMind。它会让你的眼睛流血。

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.

几个基于包的解决方案来解决这个问题。 流星指南建议 publish-composite

There are several package-based solutions to this problem. The meteor guide recommends publish-composite.

如果您发现使用基于包的解决方案的想法是不可接受的,请仔细查看加入客户部分noreferrer>反应加入流星。它很干净,但需要更多用户的等待。如果您希望在模板级别激活订阅,请参阅我在模板加入上的帖子。

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屋!

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