Skip to content

Conversation

@jordandrako
Copy link
Contributor

@jordandrako jordandrako commented Apr 18, 2018

Pull request checklist

Description of changes

  • Add isEqual (and isNotEqual function to utilities package that compares strings, numbers, arrays and objects more thoroughly than array1 === array2 or newProps.items === this.props.items.
  • Add unit tests for new functions.

Focus areas to test

Test if this breaks List shouldComponentUpdate check and if it functions any better than a simple ===.

@jordandrako jordandrako requested review from aditima and dzearing April 18, 2018 21:09
@jordandrako jordandrako requested a review from cschleiden as a code owner April 18, 2018 21:09
@jordandrako jordandrako changed the title New isEqual utility Add isEqual and isNotEqual utility Apr 18, 2018
Copy link
Contributor

@cliffkoh cliffkoh left a 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.

@@ -0,0 +1,82 @@
// tslint:disable-next-line no-any
export const isEqual = (itemA: any, itemB: any): boolean => {
Copy link
Contributor

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 :)

@dzearing dzearing closed this Apr 19, 2018
@dzearing dzearing reopened this Apr 19, 2018
// 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.
Copy link
Contributor

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 :(

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jordandrako
Copy link
Contributor Author

Wow, sometimes I need to take break before switching branches and committing...

@cliffkoh
Copy link
Contributor

"the NOT same" is back :P Would you like me to fix it for you?

@jordandrako
Copy link
Contributor Author

jordandrako commented Apr 19, 2018 via email

Jordan Janzen added 2 commits April 19, 2018 12:58
@jordandrako
Copy link
Contributor Author

Taking a break now, I swear...

@cliffkoh
Copy link
Contributor

Don't stress about it :) Thanks for cleaning up!

@cliffkoh
Copy link
Contributor

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).

@jordandrako
Copy link
Contributor Author

jordandrako commented Apr 19, 2018

Are you suggesting adding lodash as a dependency in the utilities package? Wouldn't that drastically increase our bundle size?
Or just isEqual from lodash?

@cliffkoh
Copy link
Contributor

No, either

  1. The full lodash package and rely on tree shaking to ensure a bundle size that is no greater than if we wrote it ourselves or

  2. Just the lodash isEqual npm standalone package (which we won't benefit from dedupe however).

This is just me thinking out loud though - I am not recommending a switch at the moment :)

@jordandrako
Copy link
Contributor Author

Something to think about, thanks for the suggestion.

@dzearing dzearing merged commit 23d8cfd into microsoft:master Apr 26, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 27, 2018
* 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)
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 27, 2018
* 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)
@jordandrako jordandrako deleted the feature/isEqual-function branch May 15, 2018 22:32
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List: Add prop to allow deep compare on list content updates, and document pure/immutable defaults.

3 participants