-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve property change notifications for records #2998
Conversation
1591366
to
244db37
Compare
var length = keys.length; | ||
|
||
original = merge({}, this._data); | ||
original = merge(original, this._attributes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure this is correct, as if you consider user applying changes after sending to the server, even if server sends a different value, it will not show up once you get it as an attr, as the local change will win
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're in the middle of a save we have values in �_inFlightAttributes
and that will win over _attributes
�.
var person = store.push('person', { id: 1, name: 'Tomster' });
person.set('name', 'Yehuda');
person.save();
// => request { name: 'Yehuda' }
person.set('name', 'Tom');
// <= response { name: 'Yehuda' }
_data
will contain { name: 'Tomster' }
_attributes
will contain { name: 'Tom' }
_inFlightAttributes
will contain { name: 'Yehuda' }
We will compare payload ({ name: 'Yehuda' }
) to the merged original ({ name: 'Yehuda' }
) and trigger no change.
Isn't this the correct behavior? We have { name: 'Tom' }
locally (since we changed that) and we still do, without triggering observer. If we want to get back to { name: 'Yehuda' }
we should do a rollback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, if the server were to return something completely different, say { name: 'Igor' }
, we would get a trigger, but the value would remain { name: 'Tom' }
. That might be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but we would get even if you didn't merge in attributes, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required for the scenario in test https://github.com/emberjs/data/pull/2998/files#diff-56dbbdcd2b2c38cfe44c52bec2b99646R55
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, then the order seems wrong, it should be inflight then attributes?
var keys = Ember.keys(updates); | ||
var length = keys.length; | ||
|
||
original = merge({}, this._data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ember.create(null) instead of {}
@wecc what needs to happen for this to get merged? |
@bmac needs to address the comments in here to make sure it's working as intended. |
@bmac didn't you move this into a new pr? |
This PR improves how we trigger property changes when pushing data to the store/a record.
Previously we only cared about comparing new data with
model._data
, this resulted in weird behavior in a couple of scenarios:Fixes #2937, fixes #2900