Created
April 28, 2012 04:57
-
-
Save bradleypriest/2516136 to your computer and use it in GitHub Desktop.
Ember Hack
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
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