I have a template containing a chart displayed using MorrisJS. The chart needs to be updated when the session variable changes currentData, so I made it a reactive data source with:
Template.chart.rendered = function() {
var template = this;
Deps.autorun(function(c) {
if(template.__component__.dom.parentNode() === null) {
c.stop();
return;
}
var results = Session.get('currentData');
Morris.Bar({element: template.$(".chart-container"), data: results, ...});
});
};
Notice how I do a pretty terrible check when to stop autostart above. This was necessary because without it, when I go from the page using the template (I use iron-router) to another page and back, I get warnings in the log, for example, "I can’t choose in remote DomRange." I am sure this is happening because the template instance has been deleted, but autostart is still running.
, - . () , () , DOM?
created destroyed, , .