* Performs equality by iterating through keys on an object and returning false * when any key has values which are not strictly equal between the arguments. * Returns true when the values of all keys are strictly equal.
(objA, objB)
| 34 | * Returns true when the values of all keys are strictly equal. |
| 35 | */ |
| 36 | function shallowEqual(objA, objB) { |
| 37 | if (is(objA, objB)) { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | if ( |
| 42 | typeof objA !== 'object' || |
| 43 | objA === null || |
| 44 | typeof objB !== 'object' || |
| 45 | objB === null |
| 46 | ) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | const keysA = Object.keys(objA); |
| 51 | const keysB = Object.keys(objB); |
| 52 | |
| 53 | if (keysA.length !== keysB.length) { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | // Test for A's keys different from B. |
| 58 | for (let i = 0; i < keysA.length; i++) { |
| 59 | if ( |
| 60 | !hasOwnProperty.call(objB, keysA[i]) || |
| 61 | !is(objA[keysA[i]], objB[keysA[i]]) |
| 62 | ) { |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | export default shallowEqual; |
| 71 | /* src: https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js */ |
no test coverage detected