-
-
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
[BUGFIX beta] fix for lastObject/firstObject update issue #15510
Conversation
propertyWillChange(array, 'lastObject', meta); | ||
propertyDidChange(array, 'lastObject', meta); | ||
if (cache !== undefined) { | ||
if (cache.firstObject !== undefined && startIdx === 0 && objectAt(array, 0) !== cacheFor.get(cache, 'firstObject')) { |
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.
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.
yeah but you need to invalidate cp when it changes 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.
If the index for firstObject / lastObject changed, then we should broadcast. Even if the object is equal. That means we wont need both the objectAt stuff and the range based detection.
2220610
to
45ebc8f
Compare
I updated my PR, so it does not call |
2754363
to
b036634
Compare
} | ||
if (cache !== undefined) { | ||
if (cache.firstObject !== undefined && startIdx === 0) { | ||
propertyWillChange(array, 'firstObject'); |
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 PR drops && (addAmt > 0 || removeAmt > 0)
because we can safely assume one of those must be > 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.
(which is fine, just want to confirm)
|
||
let lastIndex = length - delta - 1; | ||
let lastAffectedIndex = startIdx + removedAmount; | ||
if (lastIndex < lastAffectedIndex) { |
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 think this will miss cases where lastObject
changes from negative indices, eg
[0, 1, 2, 3].replace(-2, 2);
// => [0, 1]
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.
thanks, was not sure if negative startIndex could be passed will handle that
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.
awesome thanks @bekzod 👍
@@ -54,4 +54,26 @@ suite.test('[A,B,C].pushObject(X) => [A,B,C,X] + notify', function() { | |||
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); | |||
}); | |||
|
|||
suite.test('[A,B,C,C].pushObject(A) => [A,B,C,C] + notify', function() { |
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'll need a test for removing the tail from a negative index
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.
added that, you could take another shot when you have time, thanks
8c953db
to
f3e2ffd
Compare
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.
LGTM
@@ -126,6 +126,27 @@ suite.test('[A,B,C,D].replace(2,2) => [A,B] + notify', function() { | |||
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); | |||
}); | |||
|
|||
suite.test('[A,B,C,D].replace(-1,1) => [A,B,C] + notify', function() { |
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.
👍
let delta = addedAmount - removedAmount; | ||
let previousLength = length - delta; | ||
|
||
let normalStartIdx = startIdx < 0 ? previousLength + startIdx : 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.
👍
@krisselden bugfix beta or let it ride the canary train? |
chatted with @krisselden hes ok with |
@bekzod can you squash, and prefix with |
f3e2ffd
to
5752d95
Compare
@stefanpenner done |
enhanced #15110 PR, @stefanpenner