-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Avoid indexOf() during unmounting a root in the hook #7496
Conversation
itemMap.delete(id); | ||
return; | ||
} else { |
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 replaced early returns with branches because it makes these two paths clearer in my opinion.
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, I agree.
if (canUseCollections) { | ||
return Array.from(rootIDSet.keys()); | ||
} else { | ||
return Object.keys(rootByKey).map(getIDFromKey); |
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 stored the id as the value then this could be Object.values(rootByKey). I suppose we don't know that's polyfilled though.
lgtm |
|
||
function getRegisteredIDs() { | ||
if (canUseCollections) { | ||
return Array.from(itemMap.keys()); |
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.
.keys()
is not yet supported in all implementations, IE supposedly does not support this. EDIT: Array.from
is even less widely supported.
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 check for Array.from in canUseCollections.
Do you mean that a native Map may exist without Map.prototype.keys?
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.
Seems so (thanks for the tip!) I'll update to check for keys() specifically.
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.
My bad I missed it. It should sufficiently cover the case of .keys()
I imagine 👍 EDIT: Yep, .keys()
is not part of "basic support".
* Avoid indexOf() during unmounting a root in the hook * Check for (Map|Set).prototype.keys (cherry picked from commit 4847578)
Addresses @spicyj’s concerns in #7491 (comment).