Last active
February 13, 2018 15:11
-
-
Save stepankuzmin/11237d10f217850943d20268903e49d7 to your computer and use it in GitHub Desktop.
shouldUpdateImmutable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { is, isImmutable } from 'immutable'; | |
| import { shouldUpdate, shallowEqual } from 'recompose'; | |
| const shouldUpdateImmutable = shouldUpdate((props, nextProps) => { | |
| const keys = Object.keys(props); | |
| const nextKeys = Object.keys(nextProps); | |
| if (keys.length !== nextKeys.length) { | |
| return true; | |
| } | |
| for (let i = 0; i < keys.length; i += 1) { | |
| const key = keys[i]; | |
| if (!hasOwnProperty.call(nextProps, key)) { | |
| return true; | |
| } | |
| const prop = props[key]; | |
| const nextProp = nextProps[key]; | |
| if (isImmutable(prop) && !is(prop, nextProp)) { | |
| return true; | |
| } | |
| if (!shallowEqual(prop, nextProp)) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| }); | |
| export default shouldUpdateImmutable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment