-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add isEqual and isNotEqual utility #4603
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
Add isEqual and isNotEqual utility #4603
Conversation
- compare values and types of arrays, objects, numbers, and strings
cliffkoh
left a comment
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.
Please add the JSDoc. Otherwise LGTM.
packages/utilities/src/isEqual.ts
Outdated
| @@ -0,0 +1,82 @@ | |||
| // tslint:disable-next-line no-any | |||
| export const isEqual = (itemA: any, itemB: any): boolean => { | |||
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.
Please have JSDoc documenting this function :)
packages/utilities/src/isEqual.ts
Outdated
| // tslint:disable-next-line no-any | ||
| export const isEqual = (itemA: any, itemB: any): boolean => { | ||
| /** | ||
| * Checks if the first and second items are the NOT same recursively. Use for checking arrays and objects. |
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.
You have copy and paste issues unfortunately :(
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.
Also for isNotEqual, you probably want to fix the doc to say are NOT the same, recursively. instead.
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.
Whoops, thanks for catching that. Fixed my itchy copy+paste trigger finger.
|
Wow, sometimes I need to take break before switching branches and committing... |
|
"the NOT same" is back :P Would you like me to fix it for you? |
|
Taking a break now, I swear... |
|
Don't stress about it :) Thanks for cleaning up! |
|
LGTM to merge. Just thinking out loud though, I wonder if it might have been better for Fabric to use say, lodash's isEqual rather than implementing our own version. This might possibly allow dedupe to take place in apps during the bundling phase for any apps that uses lodash as well.(https://npmcharts.com/compare/lodash,underscore,ramda). Then again, it is probably not a big deal since there's bunch of conditions needed before it can happen (lodash will need to resolve to the same version in both the app and Fabric UI React). |
|
Are you suggesting adding lodash as a dependency in the utilities package? Wouldn't that drastically increase our bundle size? |
|
No, either
This is just me thinking out loud though - I am not recommending a switch at the moment :) |
|
Something to think about, thanks for the suggestion. |
* master: Added className to Calendar component (microsoft#4680) Fix bug for OWA+Safari+popup (microsoft#4681) Add optional props for custom divider rendering (microsoft#4687) Update package.json Add isEqual and isNotEqual utility (microsoft#4603) Fix minor typos (microsoft#4683) Allow function to be passed to Customizer settings/scopedSettings (microsoft#4677)
* master: Added className to Calendar component (microsoft#4680) Fix bug for OWA+Safari+popup (microsoft#4681) Add optional props for custom divider rendering (microsoft#4687) Update package.json Add isEqual and isNotEqual utility (microsoft#4603) Fix minor typos (microsoft#4683) Allow function to be passed to Customizer settings/scopedSettings (microsoft#4677)
Pull request checklist
$ npm run changeDescription of changes
isEqual(andisNotEqualfunction to utilities package that compares strings, numbers, arrays and objects more thoroughly thanarray1 === array2ornewProps.items === this.props.items.Focus areas to test
Test if this breaks List
shouldComponentUpdatecheck and if it functions any better than a simple===.