-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Update a test to fail #14843 #15110
Update a test to fail #14843 #15110
Conversation
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.
Left some notes, if we decide to proceed.
Would love @krisselden's input
if (cache.firstObject !== undefined && | ||
objectAt(array, 0) !== cacheFor.get(cache, 'firstObject')) { | ||
((startIdx === 0 && (addAmt > 0 || removeAmt > 0)) || |
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.
should we still include objectAt(array, 0) !== cacheFor.get(cache, 'firstObject')
guard?
objectAt(array, get(array, 'length') - 1) !== cacheFor.get(cache, 'lastObject')) { | ||
((startIdx >= length && addAmt > 0) || | ||
(startIdx >= 0 && (startIdx + removeAmt >= length)) || | ||
(startIdx < 0 && (removeAmt >= -startIdx)))) { |
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.
should we still include objectAt(array, get(array, 'length') - 1) !== cacheFor.get(cache, 'lastObject')) {
guard ?
@@ -142,17 +142,23 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) { | |||
let cache = meta && meta.readableCache(); | |||
|
|||
if (cache) { | |||
let length = get(array, 'length') + removeAmt - addAmt; |
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.
we should likely avoid this get
if we are not needing it.
This is getting complicated, if we go down this path we should do a helper function that can be unit tested (and more readable).
@@ -135,11 +135,22 @@ suite.test('[A,B,C].insertAt(1,X) => [A,X,B,C] + notify', function() { | |||
let after = [before[0], item, before[1], before[2]]; | |||
let obj = this.newObject(before); | |||
let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); | |||
let objectAtCalls = []; | |||
|
|||
let objectAt = obj.objectAt; |
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.
we will require more test permutations, as the above code has many bounds
Three possible courses of action:
|
☔ The latest upstream changes (presumably #15210) made this pull request unmergeable. Please resolve the merge conflicts. |
@stefanpenner sure, will look at it |
maybe following code is a bit clearer (tested with new test) ? @stefanpenner @hjdivad
also can |
I think the approach suggested is good enough, cannot think of better way for now will improve this once merged if I get any better ideas |
@bekzod nice, are you able to do the rebase + fix any failing tests? Feel free to open a new PR. |
Closed in favour of #15510 |
Yes, the semantics mirror those of splice |
Update a test to fail #14843 and provide example code to illustrate the change suggested in that issue.
Before this can be merged we'd need to decide to deprecate the current semantics of
firstObject
andlastObject
. The trade-off is between havingobjectAt
called in nearly every case for array mutations, or not detecting that[A, B].insertAt(0, A)
does not changefirstObject
.If that tradeoff is made, we should probably feature flag & deprecate the existing behaviour.