Replace object outright when updates are constant

This commit is contained in:
Aaron Jensen 2015-08-05 04:28:32 -07:00
parent 64b027ae81
commit cc42bbb2a4
3 changed files with 10 additions and 0 deletions

View File

@ -3,6 +3,7 @@
## [unreleased]
* Add `u.if` to conditionally update objects.
* Add `u.map` to update all values in an array or object.
* Replace object outright if null or constant givens as `updates`.
## [0.3.1]
* Actually expose `u.in`.

View File

@ -48,6 +48,10 @@ function update(updates, object) {
return updates(object);
}
if (updates === null || typeof updates !== 'object') {
return updates;
}
const resolvedUpdates = resolveUpdates(updates, object);
if (isEmpty(resolvedUpdates)) {

View File

@ -37,6 +37,11 @@ describe('updeep', () => {
expect(result).to.deep.equal([1, 7, 3]);
});
it('replaces the object outright if updates are a constant', () => {
expect(u(3, {})).to.equal(3);
expect(u(null, {})).to.be.null;
});
it('can add an element to an array', () => {
const object = [];
const result = u({ 0: 3 }, object);