Skip to content

Instantly share code, notes, and snippets.

@bradleypriest
Created April 28, 2012 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradleypriest/2516136 to your computer and use it in GitHub Desktop.
Save bradleypriest/2516136 to your computer and use it in GitHub Desktop.
Ember Hack
App.ObjectWatcher = Ember.Object.create({
methodCounter: 0,
observeOnce: function(object, property, callback) {
var aroundCallbackName, callbackName;
callbackName = "_method" + (this.methodCounter++);
aroundCallbackName = callbackName.slice(1);
this[callbackName] = callback;
this[aroundCallbackName] = function() {
this[callbackName]();
object.removeObserver(property, this, aroundCallbackName);
delete this[aroundCallbackName];
return delete this[callbackName];
};
object.addObserver(property, this, aroundCallbackName);
return object;
}
});
App.ObjectWatcher.observeOnce(family, 'isNew', function() {
console.log("Object saved to server")
App.routeManager.set('location', "inventory/" + family.get('id') + "/edit");
});
App.store.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment