Skip to content

Commit

Permalink
fix: shallowEqual(null, null) shold be true
Browse files Browse the repository at this point in the history
  • Loading branch information
taichiyi committed Aug 22, 2020
1 parent aaa405e commit 3371308
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/nerv-utils/__tests__/shallow-equal.spec.js
Expand Up @@ -11,6 +11,7 @@ describe('shallowEqual', () => {
const g = { a: 1, v: arr1 }
expect(shallowEqual(a, b)).not.toBeTruthy()
expect(shallowEqual(null, 110)).toBeFalsy()
expect(shallowEqual(null, null)).toBeTruthy()
expect(shallowEqual(+0, -0)).toBeTruthy()
expect(shallowEqual([], [1])).toBeFalsy()
expect(shallowEqual(a, c)).toBeTruthy()
Expand Down
6 changes: 3 additions & 3 deletions packages/nerv-utils/src/shallow-equal.ts
Expand Up @@ -8,12 +8,12 @@ Object.is = Object.is || function (x, y) {
}

export default function shallowEqual (obj1, obj2) {
if (obj1 === null || obj2 === null) {
return false
}
if (Object.is(obj1, obj2)) {
return true
}
if (obj1 === null || obj2 === null) {
return false
}
const obj1Keys = obj1 ? Object.keys(obj1) : []
const obj2Keys = obj2 ? Object.keys(obj2) : []
if (obj1Keys.length !== obj2Keys.length) {
Expand Down

0 comments on commit 3371308

Please sign in to comment.