I have built a list using Meteor. I do not want the entire list to be reactive, i.e. auto-update when the data changes. However, I do want the title of a list item to update if the data relating to that list item changes. I am inserting the list items using Blaze.renderWithData
, so how can I achieve this?
Asked
Active
Viewed 604 times
0

Michel Floyd
- 18,793
- 4
- 24
- 39

JoeTidee
- 24,754
- 25
- 104
- 149
1 Answers
0
Use two helpers, a non-reactive one which returns the cursor and a reactive one which returns the title. To make something non-reactive, use Tracker.nonreactive, (related question).
In the following contrived example I'm returning a reactive title that includes the cursor count if non-zero while the cursor returned from the helper is non-reactive.
subHandle = Meteor.subscribe('mySubscription');
Template.foo.helpers({
cursor: function(){
if ( subHandle.ready() ) return Tracker.nonreactive(function() {
return myCollection.find(query,options);
});
}),
title: function(){
var nDocs = myCollection.find(query,options).count();
if ( nDocs ) return "Title (" + nDocs + ")";
else return "Title";
}
});
Update: Modified to deal with the subscription handle being ready so that the nonreactive function is called for the first time with a ready subscription.
Here's a Meteorpad with a working example. You can see that the total points updates as you add points to players but the player scores and sort never change.

Community
- 1
- 1

Michel Floyd
- 18,793
- 4
- 24
- 39
-
@ Michel Floyd Are you suggesting it can't be done when using Blaze.renderWithData ? – JoeTidee Sep 13 '15 at 19:41
-
Not at all. These helpers can be on the template that embeds the dynamic template for example. I guess in that case you wouldn't need the `cursor` helper, you would just use `Tracker.nonreactive` to get the data context for your `Blaze.renderWithData()` – Michel Floyd Sep 13 '15 at 19:51
-
@ Michel Floyd - Would you mind adding and example using Blaze.renderWithData() to the answer you provided? – JoeTidee Sep 14 '15 at 08:10