Skip to content

Commit

Permalink
fix(immutables): handle nil values in same tool
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonnet committed Aug 14, 2020
1 parent 9f23bcc commit 554ef64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/immutables.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ export function setPath(target, path, value, index = 0) {
export function same(
a,
b,
properties = a !== b && uniq(concat(keys(a), keys(b))),
properties = a !== b &&
a != null &&
b != null &&
uniq(concat(keys(a), keys(b))),
deep = false,
) {
/*
Expand All @@ -190,6 +193,9 @@ export function same(
if (a === b) {
return true
}
if (a == null || b == null) {
return false
}
const { length } = properties
for (let i = 0; i < length; i++) {
const property = properties[i]
Expand Down
3 changes: 3 additions & 0 deletions src/tests/immutables.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ test('same', (assert) => {
same({ a }, { a: { b: 1 } }, ['a.b'], true),
'deeply dissimilar object',
)
assert.false(same(a, null), 'left different to null')
assert.false(same(null, b), 'right different to null')
assert.true(same(null, null), 'similar if both are null')
})

test('different', (assert) => {
Expand Down

0 comments on commit 554ef64

Please sign in to comment.