-
Notifications
You must be signed in to change notification settings - Fork 138
Switch to passing only the current-change in 'changes' emit #387
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
Conversation
47e5ed0
to
d0935c6
Compare
@jmdobry Added some comments in the code for points of interest (will extract / force-push them out later). |
Also added |
const changeHistory = _get(changeHistoryPath) || [] | ||
_set(changeHistoryPath, changeHistory) | ||
changeHistory.push(changeRecord) | ||
if (!this[noChangeHistoryPath]) { |
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.
Shouldn't this be
if (!_get(noChangeHistoryPath)) {
Can add a |
assert.equal(Object.keys(changes.removed).length, 0) | ||
assert.equal(changes.changed.name, 'updated foo', "Only the property changed was emitted in the changeSet") | ||
done() | ||
}, 5) |
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.
I saw the other tests using timeout - but something like an eventloop.after(function() {}) would be a preferable approach for testing, not sure how difficult that is to do ?
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.
In this case, something like this might work:
setImmediate(function () {...});
however, the tests need to work in a bunch of different browsers, and I'm not sure how cross-browser setImmediate
is, so setTimeout
might be just be good enough. See https://github.com/js-data/js-data/blob/master/karma.conf.js#L3
re:
Should there be some standard interface for passing mapper options down to the record? e.g. recordDefaults? atm for example mapper has |
4b60d8a
to
1981677
Compare
That If a record wants to know what the |
@jmdobry I see, so you'd prefer that changing |
I was thinking that the record would look at the mapper's setting just once, when the record is constructed. After the record is constructed, you'd control the setting on the record itself. Does that sound okay? |
That's what I have atm: https://github.com/js-data/js-data/pull/387/files#diff-513adbc50fa5d7122afa60fa3f4d25cbR137 |
d4ba485
to
9439fc8
Compare
LGTM, will merge tomorrow. |
* check that mapper is defined before checking keepChangeHistory
}), | ||
|
||
/* The previous test has a property set and changed back within a single event loop | ||
* So no listener is ever called. |
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.
Just added a code comment to clarify the reason for adding the second test.
This changes the diff function to use the previous
prop, value
pair rather than the_get('previous')
which always diffs the committed state. #372One difference that accompanies this change is that while before a single changeHistory() entry contained all the changes to get to that history from
previous
now they would need to be merged. I'm not sure what the general practical applications for changeHistory are, so I don't know how having sparse vs. full-objects affects those.