admin管理员组文章数量:1245838
In my Meteor template, I have a function called ohlcInit()
that is autorun when new data is available in Mongo:
Template.Live.rendered = function(){
function ohlcInit() {
// putations run here
}
Tracker.autorun(function() {
ohlcInit();
});
};
This works great while the user is on the page/template in which this is all defined, but as soon as the user navigates to another URL on the site and the template is destroyed, errors get thrown in the console:
Exception from Tracker repute function: undefined is not a function TypeError: undefined is not a function at ohlcInit (http://localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaaa9ed200fe3e987:271:33) at http://localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaaa9ed200fe3e987:306:5 at Tracker.Computation._pute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) at Tracker.Computation._repute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:302:14) at Tracker.flush (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:430:14)
How do you safely stop/end the autorun putation when a user navigates away to a new URL/template?
I am using iron:router
.
In my Meteor template, I have a function called ohlcInit()
that is autorun when new data is available in Mongo:
Template.Live.rendered = function(){
function ohlcInit() {
// putations run here
}
Tracker.autorun(function() {
ohlcInit();
});
};
This works great while the user is on the page/template in which this is all defined, but as soon as the user navigates to another URL on the site and the template is destroyed, errors get thrown in the console:
Exception from Tracker repute function: undefined is not a function TypeError: undefined is not a function at ohlcInit (http://localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaaa9ed200fe3e987:271:33) at http://localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaaa9ed200fe3e987:306:5 at Tracker.Computation._pute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) at Tracker.Computation._repute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:302:14) at Tracker.flush (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:430:14)
How do you safely stop/end the autorun putation when a user navigates away to a new URL/template?
I am using iron:router
.
1 Answer
Reset to default 16Use the new Template.autorun function, which automatically cleans itself up after the template is destroyed. To use it inside of a rendered
callback, just replace Tracker.autorun
with this.autorun
.
本文标签: javascriptMeteorStop Tracker Autorun when Template is Destroyed (user leaves page)Stack Overflow
版权声明:本文标题:javascript - Meteor - Stop Tracker Autorun when Template is Destroyed (user leaves page) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740230889a2245565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论