ember_data_example
ember_data_example copied to clipboard
is there more clean way to implement transitionAfterSave?
in ember_data_example github source code. It use this approach
transitionAfterSave: function() {
// when creating new records, it's necessary to wait for the record to be assigned
// an id before we can transition to its route (which depends on its id)
if (this.get('content.id')) {
this.transitionToRoute('contact', this.get('content'));
}
}.observes('content.id'),
It works fine, but maybe, this function will be executed whenever model's ID property is changed. I'm finding some more semantic way.
I want transition to be executed when the model's status is changed to 'isDirty' = false && 'isNew' == true form 'isDirty' = true, 'isNew' = false.
How can I implement this?
It would be much preferable to monitor didCreate
. However, the observer is an unfortunate hack around https://github.com/emberjs/data/issues/405
The observer is only used to transition away after created records have been materialized. There's no danger of ids being changed (except from null -> server_assigned_id) in this application.
I'll leave this issue open until we can remove this hack.
[edit] Nether mind, I though it was an ember issue
github needs to be more clear in marking cross-project issue links...
As emberjs/data#405 is now resolved, I think this could be updated and closed as well.
@ZenCocoon you're right, we should now be able to put a listener on the didCreate event.
It looks like there are still issues: https://github.com/emberjs/data/issues/405#issuecomment-17939209