Skip to content

Instantly share code, notes, and snippets.

@bobbysciacchitano
Last active August 29, 2015 14:07
Show Gist options
  • Save bobbysciacchitano/b183b873b61fc8948b70 to your computer and use it in GitHub Desktop.
Save bobbysciacchitano/b183b873b61fc8948b70 to your computer and use it in GitHub Desktop.
Useful Ember tricks
// Refresh a route:
// In the route you want to refresh, you can place the following into an action:
this.refresh();
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