3
votes

I am using EmberJS with Ember Data (Revision 11) and am trying to transition to another route when a transaction has completed successfully. The problem is this page allows edits to the model as well as adding and removing items to a hasMany collection on that model.

What I currently have is as follows:

myModel.one "didUpdate", this, ->
    @transitionTo "anotherRoute", myModel

myModel.transaction.commit()

Which will only ever transition if the myModel has been changed not if any of it's hasMany children have changed as well.

I am really looking for a way to either:

  • Have the didUpdate event run when all the hasMany children for myModel have successfully saved
  • Hook into a call back on the transaction when all models have be successfully persisted.
1

1 Answers

3
votes

I've run into this issue as well. My current solution is to observe the transaction state:

observer = (target, path) =>
  if target.get(path) is 'saved'
    target.removeObserver path, null, observer
    @doSomething()

@get('content').addObserver 'stateManager.currentState.name', null, observer
@get('content.transaction').commit()

The fact that didUpdate does not work might be a bug. If I define the callback directly on the model it does get called.