Skip to content

Instantly share code, notes, and snippets.

@alexspeller
Forked from kurko/refreshable_models.js
Last active December 23, 2015 11:49
Show Gist options
  • Save alexspeller/6631309 to your computer and use it in GitHub Desktop.
Save alexspeller/6631309 to your computer and use it in GitHub Desktop.
Admin.RefreshableModel = Em.Object.extend({
/**
* Keeps reloading a given model from the server. To stop this process, just
* kill the `timer` variable.
*/
reload: function(model) {
if(this.timer) { this.stop(); }
this.model = model;
this.timer = Em.run.later(this, '_reload', 15000);
},
_reload: function() {
this.model.reload();
},
stop: function() {
Em.run.cancel(this.timer);
}
}
Admin.ClientRoute = Ember.Route.extend({
});
Admin.ClientIndexRoute = Ember.Route.extend({
deactivate: function() {
this.get('liveModelReload').stop();
},
liveModelReload: function() {
return new Admin.RefreshableModel();
}.property()
model: function(params) {
return this.store.find('client', this.modelFor("client").get("id"));
},
afterModel: function(model, transition) {
this.get('liveModelReload').reload(model);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment