-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[charts] Plugin selector memoization issue #16575
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fastArrayCompare } from '../fastArrayCompare'; | ||
import { fastObjectShallowCompare } from '../fastObjectShallowCompare'; | ||
|
||
/** | ||
* Fast shallow compare. | ||
* | ||
* Builds on top of `fastArrayCompare` and `fastObjectShallowCompare` and uses them for their respective types. | ||
* | ||
* @returns true if `a` and `b` are equal. | ||
*/ | ||
export function fastShallowCompare(a: any, b: any) { | ||
if (Array.isArray(a)) { | ||
return fastArrayCompare(a, b); | ||
} | ||
if (b instanceof Object) { | ||
return fastObjectShallowCompare(a, b); | ||
} | ||
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is a bit confusing to me, why is it checking Also the object check should probably be In general I wouldn't advise using the "fast" methods as generic equality check functions, the tradeoff for "fast" is usually correctness in edge-cases. Imo we should maybe even mark those functions as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Mistake
Should we use a "complete compare" instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on the use-case. Maybe I should have written more in the jsdoc, but the fast object compare is only really meant for record objects like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also note that when I used Imho, selectors should receive standard arguments, not bag-of-data arguments like |
||
return Object.is(a, b); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './fastShallowCompare'; |
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 use this? I guess it makes sense. Is there any way to remove code when building for a release?
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.
equalityCheck: process.env.NODE_ENV !== 'production' ? compain : fast
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 is mostly for discussion on the issue, it does not depict the final solution. 😄
I think the discussion would be more if we want to use
fastShallowCompare
directly, which would fix the problems everywhere.Or if we want to have this
complain
function, and manually fix those when we detect them.