ember_data_example icon indicating copy to clipboard operation
ember_data_example copied to clipboard

is there more clean way to implement transitionAfterSave?

Open synthresin opened this issue 12 years ago • 5 comments

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?

synthresin avatar Feb 20 '13 13:02 synthresin

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.

dgeb avatar Feb 20 '13 15:02 dgeb

[edit] Nether mind, I though it was an ember issue

github needs to be more clear in marking cross-project issue links...

tchak avatar Feb 22 '13 14:02 tchak

As emberjs/data#405 is now resolved, I think this could be updated and closed as well.

ZenCocoon avatar May 15 '13 11:05 ZenCocoon

@ZenCocoon you're right, we should now be able to put a listener on the didCreate event.

sly7-7 avatar May 15 '13 12:05 sly7-7

It looks like there are still issues: https://github.com/emberjs/data/issues/405#issuecomment-17939209

lulezi avatar May 15 '13 14:05 lulezi