ember-cli-stained-by-children icon indicating copy to clipboard operation
ember-cli-stained-by-children copied to clipboard

A bug in clean-embedded-children

Open sergetab opened this issue 9 years ago • 6 comments

Found a bug in the clean-embedded-children.

After doing this

child.send('willCommit');
child.set('_attributes', {});
child.send('didCommit');

the child will become non-dirty, BUT all changed attributes will have old(original) value. So if, for example, you change a field again to it's previous value, it would not become dirty.

After some debugging, the right way to do it I think is

child.send('willCommit');
child._inFlightAttributes = child._attributes;
child._attributes = Ember.create(null);
child.send('didCommit');

That way after 'didCommit' all values from '_inFlightAttributes ' will be merged to '_data' automatically, so that values do update.

Also I think doing 'willCommit' and 'didCommit' for rollback is redundant.

sergetab avatar May 05 '15 18:05 sergetab

Can you please PR a failing test case?

lolmaus avatar May 05 '15 22:05 lolmaus

Let me try to explain it in another way instead. It is quite simple really.

Attributes are stored in three places in Ember Data _data (saved data), _attributes (dirty attribute values), _inFlightAttributes (values that are being saved and about to be applied to _data).

In your code you just clear out _attributes like this

child.set('_attributes', {}). 

That way dirty values are lost. What is missing is

child._inFlightAttributes = child._attributes;

before that. If you assign _inFlightAttributes, didCommit will merge them back to _data.

sergetab avatar May 06 '15 02:05 sergetab

Thank you for your explanation. But could you provide a sequence of steps of working with a StainedByChildren-powered model that result in the issue? I need a failing test case.

lolmaus avatar Jun 27 '15 09:06 lolmaus

Hey guys @lolmaus , @sergetab , any updates here?

Mifrill avatar Nov 19 '20 12:11 Mifrill

@Mifrill Hey comrade, this addon is entirely unmaintained and is likely to be incompatible with modern versions of Ember Data since it was relying on private API.

lolmaus avatar Nov 19 '20 12:11 lolmaus

@lolmaus okay, thanks for the quick response, will deprecate this addon for our app then, thank you!

Mifrill avatar Nov 19 '20 12:11 Mifrill