javascript - How to properly stop Meteor Tracker.autorun? -
javascript - How to properly stop Meteor Tracker.autorun? -
i have following:
meteor.startup(function() { var computation = tracker.autorun(function() { var currentchapter; currentchapter = chapters.findone({ _id: currentchapterid }); if (currentchapter) { if (currentchapter.title) { $("#input-title").val(currentchapter.title); } else { $("#input-title").val(""); } if (currentchapter.content) { $("#input-content").html(currentchapter.content); } else { $("#input-content").html(""); } } homecoming computation.stop(); }); });
right get:
exception tracker afterflush function: cannot phone call method 'stop' of undefined typeerror: cannot phone call method 'stop' of undefined
what want stop computation 1 time currentchapter
true. doing wrong?
two things:
1 - autorun function gets handle computation passed it, can stop so:
meteor.startup(function() { var computation = tracker.autorun(function(thiscomp) { var currentchapter; currentchapter = chapters.findone({ _id: currentchapterid }); if (currentchapter) { if (currentchapter.title) { $("#input-title").val(currentchapter.title); } else { $("#input-title").val(""); } if (currentchapter.content) { $("#input-content").html(currentchapter.content); } else { $("#input-content").html(""); } thiscomp.stop(); } }); });
2 - in code, computation stopped @ end of first run regardless - should stopping within if (currentchapter)
block.
javascript meteor
Comments
Post a Comment