Add u.update as alias to u

This commit is contained in:
Aaron Jensen 2015-08-06 21:40:36 -07:00
parent 339904aace
commit b6b2daf824
3 changed files with 17 additions and 3 deletions

View File

@ -3,6 +3,7 @@
## [unreleased]
* 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.
* Make `u` available at `u.update` as well.
## [0.4.0]
* Add `u.if` and `u.ifElse` to conditionally update objects. (https://github.com/substantial/updeep/issues/12)

View File

@ -81,6 +81,18 @@ var newPerson = u({
### `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
```js

View File

@ -1,12 +1,12 @@
import freeze from './freeze';
import updateIn from './updateIn';
import is from './is';
import ifElse from './ifElse';
import map from './map';
import omit from './omit';
import reject from './reject';
import withDefault from './withDefault';
import update from './update';
import updateIn from './updateIn';
import withDefault from './withDefault';
import { placeholder as _ } from 'lodash/function/curry';
@ -14,12 +14,13 @@ const u = update;
u.if = ifElse(_, _, {});
u.ifElse = ifElse;
u.updateIn = updateIn;
u.is = is;
u.freeze = freeze;
u.map = map;
u.omit = omit;
u.reject = reject;
u.update = update;
u.updateIn = updateIn;
u.withDefault = withDefault;
export default u;