From e53aa11b27e14948a6e6a29cd7225e3f92296e97 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Thu, 13 Aug 2015 20:57:57 -0700 Subject: [PATCH] Add more examples for u.updateIn --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 118b492..d1399ba 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ expect(result).toEqual({ name: "Joe Merrill", age: 22 }); ### `u.updateIn(path(, value)(, object))` -Update a single value with a simple string or array path. +Update a single value with a simple string or array path. Can be use to update nested objects, arrays, or a combination. ```js var result = u.updateIn('bunny.color', 'brown', { bunny: { color: 'black' } }); @@ -186,6 +186,12 @@ var result = u.updateIn('bunny.color', 'brown', { bunny: { color: 'black' } }); expect(result).toEqual({ bunny: { color: 'brown' } }); ``` +```js +var result = u.updateIn('0.1.color', 'brown', [[{ color: 'blue' }, { color: 'red' }], []]); + +expect(result).toEqual( [[{ color: 'blue' }, { color: 'brown' }], []]); +``` + ```js function increment(i) { return i + 1; } @@ -195,9 +201,9 @@ expect(result).toEqual({ bunny: { age: 3 } }); ``` ```js -var result = u({ pet: u.updateIn(['bunny', 'age'], 3) }, { pet: { bunny: { age: 2 } } }); +var result = u({ pets: u.updateIn([0, 'bunny', 'age'], 3) }, { pets: [{ bunny: { age: 2 } }] }); -expect(result).toEqual({ pet: { bunny: { age: 3 } } }); +expect(result).toEqual({ pets: [{ bunny: { age: 3 } }] }); ``` ### `u.constant(object)`