Set up callback after transaction

I am trying to achieve something that, it seems to me, has a simple answer, but for some reason I cannot find it by reading the source code of ember-data .

I would like to trigger an action after a specific set of changes has been made to the data warehouse. This is 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 to this isDirty custom property, but a) it does not look idiomatic and, more importantly, b) I would have to manually remove this observer at the end - which is error prone if some exception occurs between they are not deleted, for example.

Any ideas? How do you do this?

+8
ember-data
source share
1 answer

You can use didCreate and didUpdate for the model. I assume you have a user model, so that:

 MyApp.User = DS.Model.extend({ first: DS.attr('string'), page: DS.attr('string'), didUpdate: function() { //Do something }, didCreate: function() { //do something } }); 
+6
source share

All Articles