Replace object outright when updates are constant
This commit is contained in:
parent
64b027ae81
commit
cc42bbb2a4
@ -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`.
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user