Skip to content

Instantly share code, notes, and snippets.

@kurko
Created September 19, 2013 23:20
Show Gist options
  • Save kurko/6631204 to your computer and use it in GitHub Desktop.
Save kurko/6631204 to your computer and use it in GitHub Desktop.
Admin.RefreshableModel = function() {
var refreshable = this;
this.timer = null;
/**
* Keeps reloading a given model from the server. To stop this process, just
* kill the `timer` variable.
*/
this.reload = function(model) {
refreshable.timer = setTimeout(function() {
model.reload();
refreshable.reload(model);
}, 15000);
}
return {
/**
* Hits the server to reload the passed in model.
*/
observe: function(model) {
return refreshable.reload(model);
},
/**
* Stops the live reloading mechanism
*/
stop: function() {
clearTimeout(refreshable.timer);
}
}
}
Ember.Route.reopen({
deactivate: function() {
this.get('liveModelReload').stop();
},
liveModelReload: function() {
return new Admin.RefreshableModel();
}.property()
});
Admin.ClientRoute = Ember.Route.extend({
});
Admin.ClientIndexRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('client', this.modelFor("client").get("id"));
},
afterModel: function(model, transition) {
this.get('liveModelReload').observe(model);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment