Allow update to preserve empty objects

fixes #29
This commit is contained in:
Aaron Jensen 2015-08-18 04:28:19 -07:00
parent e53aa11b27
commit c083f4a330
3 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,10 @@
# Change Log # Change Log
## [unreleased]
## [0.7.1]
* Fix update omitting empty object. (https://github.com/substantial/updeep/issues/29)
## [0.7.0] ## [0.7.0]
* Add `u._` placeholder for curried functions. * Add `u._` placeholder for curried functions.
* Add `u.constant` for replacing an object outright. (https://github.com/substantial/updeep/issues/10) * Add `u.constant` for replacing an object outright. (https://github.com/substantial/updeep/issues/10)
@ -60,7 +65,8 @@
## 0.1.0 ## 0.1.0
* Initial release * Initial release
[unreleased]: https://github.com/aaronjensen/updeep/compare/v0.7.0...HEAD [unreleased]: https://github.com/aaronjensen/updeep/compare/v0.7.1...HEAD
[0.7.1]: https://github.com/aaronjensen/updeep/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/aaronjensen/updeep/compare/v0.6.0...v0.7.0 [0.7.0]: https://github.com/aaronjensen/updeep/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/aaronjensen/updeep/compare/v0.5.0...v0.6.0 [0.6.0]: https://github.com/aaronjensen/updeep/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/aaronjensen/updeep/compare/v0.4.0...v0.5.0 [0.5.0]: https://github.com/aaronjensen/updeep/compare/v0.4.0...v0.5.0

View File

@ -69,7 +69,7 @@ function update(updates, object, ...args) {
const resolvedUpdates = resolveUpdates(updates, defaultedObject); const resolvedUpdates = resolveUpdates(updates, defaultedObject);
if (isEmpty(resolvedUpdates)) { if (isEmpty(resolvedUpdates)) {
return object; return defaultedObject;
} }
if (Array.isArray(defaultedObject)) { if (Array.isArray(defaultedObject)) {

View File

@ -129,4 +129,9 @@ describe('updeep', () => {
result = u({ a: { b: 0 } }, { }); result = u({ a: { b: 0 } }, { });
expect(result).toEqual({ a: { b: 0 } }); expect(result).toEqual({ a: { b: 0 } });
}); });
it('preserves empty objects when empty updates are specified', () => {
const result = u({ a: {} }, {});
expect(result).toEqual({ a: {} });
});
}); });