The most easily scalable solution is to store data in a local collection - by passing an empty name, the collection will be both local and session, and therefore you can put whatever you want into it and still achieve all the advantages of reactivity. If you update the getUserPoints results in this collection, you can simply write a helper to get the corresponding value for each user, and it will automatically update.
userData = new Meteor.Collection(null); // whenever you need to call "getUserPoints" use: Meteor.call("getUserPoints", this._id, function(err, res) { userData.upsert({userId: this._id}, {$set: {userId: this._id, points: res}}); }); Template.listItem.helpers({ userPoints: function() { var pointsDoc = userData.findOne({userId: this._id}); return pointsDoc && pointsDoc.points; } });
There is an alternative use of the Tracker package (formerly Deps), which will be quickly implemented here, but inconvenient to Tracker.Dependency essence, you can configure the new Tracker.Dependency to track changes at user points:
var pointsDep = new Tracker.Dependency(); // whenever you call "getUserPoints": Meteor.call("getUserPoints", this._id, function(err, res) { ... pointsDep.changed(); });
Then just add a dummy helper to your listItem template (i.e. a helper that returns nothing by design):
<template name="listItem"> ... {{pointsCheck}} </template> Template.listItem.helpers({ pointsCheck: function() { pointsDep.depend(); } });
While this will not return anything, it will cause the template to retrieve when pointsDep.changed() called (which will be when new data about the user's points is received).
richsilv
source share