Setup a callback after a transaction has committed
ember-data, ember.js
Solution
You can use didCreate and didUpdate on the model. I'm assuming you have a user model so something like:
MyApp.User = DS.Model.extend({
first: DS.attr('string'),
page: DS.attr('string'),
didUpdate: function() {
//Do something
},
didCreate: function() {
//do something
}
});
Problem
I'm trying to achieve something that I guess has a simple answer but somehow I can't find it reading the source code of `ember-data`. I would like to trigger an action after a particular set of modifications have been committed to the datastore. This my current code: ``` var transaction = App.store.transaction(); user = App.get('currentUser'); transaction.add(user); user.set('name', "Michael Jackson"); transaction.commit(); App.navigate('dashboard'); ``` My first attempt was to add an observer over this user's `isDirty` property, but a) it doesn't seem idiomatic and more importantly b) I would have to remove manually that observer at the end - that's prone to errors if some exception raises in between and doesn't get removed, for instance. Any ideas? How would you do this?