lundi 30 novembre 2015

Ember: Detect when an object is saved

Somewhere in my ember code I have

myobject.save();

I want to detect when that saving is done. Because then the object has gotten an ID.

I know the save method returns a promise and I can use then() to execute code when saving is done. But that pattern won't work in my case.

Somewhere else in my code I am doing several things and then I want to get the ID of myobject. Then I might have to wait until the object has finished the save and has gotten the ID. I need the id because it shall be part of a transition to a dynamic route. The code in a route action handler looks like this:

myobject.DoSomeStuffAndThenSave();
....
// Do some other stuff that might take some time
....
this.transitionTo('myroute', myobject.get('id'));

I guess I need to check the isSaving flag and and in the case the isSaving flag is true, I should listen to the isUpdated event. But how do I do that?




Aucun commentaire:

Enregistrer un commentaire