Allow updating to null

Fixes #8
This commit is contained in:
Aaron Jensen 2015-08-04 21:33:27 -07:00
parent c7592a26b4
commit 08ebbf5c89
3 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,7 @@
# Change Log # Change Log
## [unreleased] ## [unreleased]
* Fix cannot update value to null (https://github.com/substantial/updeep/issues/8)
* Add umd distribution builds via webpack. (https://github.com/aaronjensen/updeep/issues/3) * Add umd distribution builds via webpack. (https://github.com/aaronjensen/updeep/issues/3)
## [0.2.2] ## [0.2.2]

View File

@ -5,7 +5,7 @@ import assign from 'lodash/object/assign';
function resolveUpdates(updates, obj = {}) { function resolveUpdates(updates, obj = {}) {
return reduce(updates, (acc, value, key) => { return reduce(updates, (acc, value, key) => {
let updatedValue = value; let updatedValue = value;
if (!Array.isArray(value) && typeof value === 'object') { if (!Array.isArray(value) && value !== null && typeof value === 'object') {
updatedValue = update(value, obj[key]); updatedValue = update(value, obj[key]);
} else if (typeof value === 'function') { } else if (typeof value === 'function') {
updatedValue = value(obj[key]); updatedValue = value(obj[key]);

View File

@ -109,4 +109,8 @@ describe('updeep', () => {
expect(Object.isFrozen(result)).to.be.true; expect(Object.isFrozen(result)).to.be.true;
expect(Object.isFrozen(result.foo)).to.be.true; expect(Object.isFrozen(result.foo)).to.be.true;
}); });
it('assigns null values', () => {
expect(u({isNull: null}, {})).to.eql({isNull: null});
});
}); });