Skip to content

Commit

Permalink
Clarify merge, mergeDeep behaviour on undefined attributes (#21,
Browse files Browse the repository at this point in the history
  • Loading branch information
guigrpa committed Mar 3, 2018
1 parent bd0d444 commit e2ad74d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,12 @@ conditions are true:

* `obj2` is `null` or `undefined`
* `obj2` is an object, but it is empty
* All attributes of `obj2` are `undefined`
* All attributes of `obj2` are referentially equal to the
corresponding attributes of `obj`
corresponding attributes of `obj1`

Note that `undefined` attributes in `obj2` do not modify the
corresponding attributes in `obj1`.

```js
obj1 = { a: 1, b: 2, c: 3 }
Expand Down Expand Up @@ -357,8 +361,12 @@ conditions are true:

* `obj2` is `null` or `undefined`
* `obj2` is an object, but it is empty
* All attributes of `obj2` are `undefined`
* All attributes of `obj2` are referentially equal to the
corresponding attributes of `obj`
corresponding attributes of `obj1`

Note that `undefined` attributes in `obj2` do not modify the
corresponding attributes in `obj1`.

```js
obj1 = { a: 1, b: 2, c: { a: 1 } }
Expand Down
19 changes: 14 additions & 5 deletions src/timm.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,10 @@ function doSetIn<T: ArrayOrObject>(
if (idx === path.length - 1) {
newValue = val;
} else {
const nestedObj = isObject(obj) && isObject(obj[key])
? obj[key]
: typeof path[idx + 1] === 'number' ? [] : {};
const nestedObj =
isObject(obj) && isObject(obj[key])
? obj[key]
: typeof path[idx + 1] === 'number' ? [] : {};
newValue = doSetIn(nestedObj, path, val, idx + 1);
}
return set(obj, key, newValue);
Expand Down Expand Up @@ -460,8 +461,12 @@ export function updateIn<T: ArrayOrObject>(
// --
// -- * `obj2` is `null` or `undefined`
// -- * `obj2` is an object, but it is empty
// -- * All attributes of `obj2` are `undefined`
// -- * All attributes of `obj2` are referentially equal to the
// -- corresponding attributes of `obj`
// -- corresponding attributes of `obj1`
// --
// -- Note that `undefined` attributes in `obj2` do not modify the
// -- corresponding attributes in `obj1`.
// --
// -- ```js
// -- obj1 = { a: 1, b: 2, c: 3 }
Expand Down Expand Up @@ -506,8 +511,12 @@ export function merge(
// --
// -- * `obj2` is `null` or `undefined`
// -- * `obj2` is an object, but it is empty
// -- * All attributes of `obj2` are `undefined`
// -- * All attributes of `obj2` are referentially equal to the
// -- corresponding attributes of `obj`
// -- corresponding attributes of `obj1`
// --
// -- Note that `undefined` attributes in `obj2` do not modify the
// -- corresponding attributes in `obj1`.
// --
// -- ```js
// -- obj1 = { a: 1, b: 2, c: { a: 1 } }
Expand Down

0 comments on commit e2ad74d

Please sign in to comment.