Reputation: 87
In my interface I have a list of items (let's call these items tasks). For each task I can assign someone to it. I pick someone to assign by hovering over a little drop down that will have a list of people I can select from. All my tasks will have the same set of users. The way it's been done right now, is the drop down is a template which has a helper to generate the list of users.
The problem is that the helper is being called on each list item. Add to that the face that I have a slightly complex function that alters the data upon retrieval. The complex function is also being called on each list item.
What I want to do is have a single reactive data point which will act as a single point of reference for the drop downs in all the list items. Thus the computations would happen only once upon page load, and all the drop downs would look to that data source. Is there a canonical way of doing this in Meteor?
My current idea is to store the computation in a var and when iterating through the list items, I check if the variable is null, and if it isn't I call the variable instead of the complex function. But there are the questions of where do I keep the var etc. Pretty sure there should be some common solution for this problem.
Edit - I should be clear on the fact that I need the users list to be reactive. Placing it in a var made it non reactive as I discovered. I'm pretty sure there's a deps requirement somewhere here but I can't wrap my head around it.
Upvotes: 0
Views: 121
Reputation: 2180
Template.tasks.created = function() {
Deps.autorun(function() {
var users;
//generate list of users and assign results to users
Template.tasks.users = users;
});
}
This way you can then access the reactive data through Template.tasks.users
or {{users}}
Upvotes: 1