Add u.update as alias to u
This commit is contained in:
parent
339904aace
commit
b6b2daf824
@ -3,6 +3,7 @@
|
|||||||
## [unreleased]
|
## [unreleased]
|
||||||
* Add `u.is` to test predicates in a single path. (https://github.com/substantial/updeep/issues/13)
|
* Add `u.is` to test predicates in a single path. (https://github.com/substantial/updeep/issues/13)
|
||||||
* Rename `u.in` to `u.updateIn`. With `u.is` and `u.if` it was too confusing.
|
* Rename `u.in` to `u.updateIn`. With `u.is` and `u.if` it was too confusing.
|
||||||
|
* Make `u` available at `u.update` as well.
|
||||||
|
|
||||||
## [0.4.0]
|
## [0.4.0]
|
||||||
* Add `u.if` and `u.ifElse` to conditionally update objects. (https://github.com/substantial/updeep/issues/12)
|
* Add `u.if` and `u.ifElse` to conditionally update objects. (https://github.com/substantial/updeep/issues/12)
|
||||||
|
12
README.md
12
README.md
@ -81,6 +81,18 @@ var newPerson = u({
|
|||||||
|
|
||||||
### `u(updates(, object))`
|
### `u(updates(, object))`
|
||||||
|
|
||||||
|
Update as many values as you want, as deeply as you want. The `updates` parameter can either be an object, a function, or a value. Everything returned from `u` is frozen recursively.
|
||||||
|
|
||||||
|
If `updates` is an object, for each key/value, it will apply the updates specified in the value to `object[key]`.
|
||||||
|
|
||||||
|
If `updates` is a function, it will call the function with `object` and return the value.
|
||||||
|
|
||||||
|
If `updates` is a value, it will return that value.
|
||||||
|
|
||||||
|
Sometimes, you may want to set an entire object to a property, or a function. In that case, you'll need to use a function to return that value, otherwise it would be interpreted as an update. Ex. `function() { return { a: 0 }; }`.
|
||||||
|
|
||||||
|
Also available at `u.update(...)`.
|
||||||
|
|
||||||
#### Simple update
|
#### Simple update
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import freeze from './freeze';
|
import freeze from './freeze';
|
||||||
import updateIn from './updateIn';
|
|
||||||
import is from './is';
|
import is from './is';
|
||||||
import ifElse from './ifElse';
|
import ifElse from './ifElse';
|
||||||
import map from './map';
|
import map from './map';
|
||||||
import omit from './omit';
|
import omit from './omit';
|
||||||
import reject from './reject';
|
import reject from './reject';
|
||||||
import withDefault from './withDefault';
|
|
||||||
import update from './update';
|
import update from './update';
|
||||||
|
import updateIn from './updateIn';
|
||||||
|
import withDefault from './withDefault';
|
||||||
|
|
||||||
import { placeholder as _ } from 'lodash/function/curry';
|
import { placeholder as _ } from 'lodash/function/curry';
|
||||||
|
|
||||||
@ -14,12 +14,13 @@ const u = update;
|
|||||||
|
|
||||||
u.if = ifElse(_, _, {});
|
u.if = ifElse(_, _, {});
|
||||||
u.ifElse = ifElse;
|
u.ifElse = ifElse;
|
||||||
u.updateIn = updateIn;
|
|
||||||
u.is = is;
|
u.is = is;
|
||||||
u.freeze = freeze;
|
u.freeze = freeze;
|
||||||
u.map = map;
|
u.map = map;
|
||||||
u.omit = omit;
|
u.omit = omit;
|
||||||
u.reject = reject;
|
u.reject = reject;
|
||||||
|
u.update = update;
|
||||||
|
u.updateIn = updateIn;
|
||||||
u.withDefault = withDefault;
|
u.withDefault = withDefault;
|
||||||
|
|
||||||
export default u;
|
export default u;
|
||||||
|
Loading…
Reference in New Issue
Block a user