Last active
August 29, 2015 14:07
-
-
Save bobbysciacchitano/b183b873b61fc8948b70 to your computer and use it in GitHub Desktop.
Useful Ember tricks
This file contains 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
// Refresh a route: | |
// In the route you want to refresh, you can place the following into an action: | |
this.refresh(); |
This file contains 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
poll: null, | |
setupController: function(controller, model) | |
{ | |
controller.set('content', model); | |
this.store.find('user', this.get('session.user_id')).then(function(user) | |
{ | |
user.get('organisations').then(function(organisations) | |
{ | |
var status = organisations.findBy('organisation', model); | |
controller.set('status', status); | |
}); | |
}); | |
this.pollUpdates(); | |
}, | |
deactivate: function() | |
{ | |
var model = this.get('controller.status'); | |
if (model.get('isDirty') && !model.get('isSaving')) | |
{ | |
model.rollback(); | |
} | |
this.stopUpdates(); | |
}, | |
pollUpdates: function() | |
{ | |
return Ember.run.later(this, function() | |
{ | |
this.modelFor('workspace/organisation').get('users').reload(); | |
this.set('poll', this.pollUpdates()); | |
}, 20000); | |
}, | |
stopUpdates: function() | |
{ | |
Ember.run.cancel(this.get('poll')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment