javascript - Template.destroyed() not called -


i'm displaying timer showing elapsed time since collection item created. however, when navigate between items (switch routes/url) timer doesn't destroyed , end having bunch of leaked timers.

i keep reference timer , kill in router prefer cleaner way , handle in template. ideas?

<template name="itemdetails">     {{elapsedtime}} </template>  template.itemdetails.onrendered = function() {     var starttime = template.currentdata().starttime;     this.timeelapsed = new reactivevar;      this.tasktimer = meteor.setinterval(function() {         var timeelapsedinms = date.now() - starttime;             var date = new date(timeelapsedinms);         var hours = (date.getutchours() < 10 ? '0' :'') + date.getutchours();         var minutes = (date.getutcminutes() < 10 ? '0' :'') + date.getutcminutes();         var seconds = (date.getutcseconds() < 10 ? '0' :'') + date.getutcseconds();          var timeelapsed = hours + ":" + minutes + ":" + seconds;         this.timeelapsed.set(timeelapsed);         console.log(timeelapsed);     }, 1000); }  template.itemdetails.helpers({  elapsedtime: function() {     return template.timeelapsed.get(); } });  template.itemdetails.ondestroyed = function() {     meteor.clearinterval(this.tasktimer); } 

i (template level) well. here quick example of how timer @ template level:

<template name="test">     <p>count: {{time}}</p> </template>  template.test.oncreated(function() {     var self = this;     self.time = new reactivevar(0);      self.tasktimer = meteor.setinterval(function() {         self.time.set(self.time.get() + 1)     }, 1000); });  template.test.ondestroyed(function() {     meteor.clearinterval(this.tasktimer); });  template.test.helpers({     time: function() {         var self = template.instance();         return self.time.get();     } }); 

i hope can continue here =)


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -