Created
September 19, 2013 23:20
-
-
Save kurko/6631204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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