From b6b2daf82431e5268130946ed8336735781cd715 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Thu, 6 Aug 2015 21:40:36 -0700 Subject: [PATCH] Add u.update as alias to u --- CHANGELOG.md | 1 + README.md | 12 ++++++++++++ lib/index.js | 7 ++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d578939..a7b8253 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 1c34d10..d75ce6b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/index.js b/lib/index.js index 97267d7..77375ea 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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;