My client subscription routines are not refreshing when I update a collection:
server/publish.js
Meteor.publish(\'decisions\', funct
The callback to Meteor.subscribe
is called when the server marks the subscription as ready, and is not a reactive context, so it won't re-run when its dependencies change. (Reactive contexts aren't inherited like closure variables, the fact the callback is physically inside of the autorun is irrelevant.) You probably want a second autorun
:
// original autorun
Deps.autorun(function() {
var decSubscription = Meteor.subscribe("decisions", Number(Session.get('decisionCursor')));
Meteor.subscribe("decisionsToModerate", Number(Session.get('decisionCursor')));
// Store the subscription handle in a session variable so that
// the new autorun re-runs if we resubscribe
Session.set("decSubscription", decSubscription);
});
// new autorun
Deps.autorun(function() {
// don't do anything if the subscription isn't ready yet
var decCursor = Session.get("decSubscription");
if (!decCursor.ready()) {
Session.set("decisionsVoted", {});
return;
}
var decisionsVoted = {};
Decisions.find({active: true}).forEach(/* ... */);
Session.set("decisionsVoted", decisionsVoted);
});
Note that we skip computing decisionsVoted
if the subscription isn't ready, otherwise when the server is sending the initial result set, we will recompute it after each individual document is sent.