File tree Expand file tree Collapse file tree 1 file changed +24
-11
lines changed Expand file tree Collapse file tree 1 file changed +24
-11
lines changed Original file line number Diff line number Diff line change 11const hasOwn = Object . prototype . hasOwnProperty
22
3- export default function shallowEqual ( a , b ) {
4- if ( a === b ) return true
3+ function is ( x , y ) {
4+ if ( x === y ) {
5+ return x !== 0 || y !== 0 || 1 / x === 1 / y
6+ } else {
7+ return x !== x && y !== y
8+ }
9+ }
10+
11+ export default function shallowEqual ( objA , objB ) {
12+ if ( is ( objA , objB ) ) return true
513
6- let countA = 0
7- let countB = 0
8-
9- for ( let key in a ) {
10- if ( hasOwn . call ( a , key ) && a [ key ] !== b [ key ] ) return false
11- countA ++
14+ if ( typeof objA !== 'object' || objA === null ||
15+ typeof objB !== 'object' || objB === null ) {
16+ return false
1217 }
1318
14- for ( let key in b ) {
15- if ( hasOwn . call ( b , key ) ) countB ++
19+ const keysA = Object . keys ( objA )
20+ const keysB = Object . keys ( objB )
21+
22+ if ( keysA . length !== keysB . length ) return false
23+
24+ for ( let i = 0 ; i < keysA . length ; i ++ ) {
25+ if ( ! hasOwn . call ( objB , keysA [ i ] ) ||
26+ ! is ( objA [ keysA [ i ] ] , objB [ keysA [ i ] ] ) ) {
27+ return false
28+ }
1629 }
1730
18- return countA === countB
31+ return true
1932}
You can’t perform that action at this time.
0 commit comments