Ember model reloading in interval
For those who are coming across this question now -- don't use setInterval
, it's been shown to cause serious memory leaks.
Use Ember's own Ember.run.later instead.
See also:
- SetTimeout vs. Ember.run.later in an ember app?
- http://guides.emberjs.com/v1.12.0/cookbook/working_with_objects/continuous_redrawing_of_views/
- https://www.slideshare.net/yoranbe/presentation-31170160
Edit: Feb 3, 2019 - Update broken links.
The model has a .reload()
method now, which you could use in a setInterval
callback. See https://stackoverflow.com/a/14183507/363073
P.S. Watch #545.
EDIT: Please see Dmitri Zagidulin's answer.
So I figured it out. For now all I need was to override didLoad method on model, in future I will probably need more complex solution, but this is adequate for now.
didLoad: function(){
var self = this;
setInterval(function() {self.reload()}, 5*60*1000); //every 5 minutes
}
In case someone needs to reload more models, good solution would be to implement this as Mixin.