From c083f4a3307e29c11940c13ff700bde7d1b4bfab Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 18 Aug 2015 04:28:19 -0700 Subject: [PATCH] Allow update to preserve empty objects fixes #29 --- CHANGELOG.md | 8 +++++++- lib/update.js | 2 +- test/updeep-spec.js | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57da2b0..337b128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [unreleased] + +## [0.7.1] +* Fix update omitting empty object. (https://github.com/substantial/updeep/issues/29) + ## [0.7.0] * Add `u._` placeholder for curried functions. * Add `u.constant` for replacing an object outright. (https://github.com/substantial/updeep/issues/10) @@ -60,7 +65,8 @@ ## 0.1.0 * 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.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 diff --git a/lib/update.js b/lib/update.js index 0421608..7927524 100644 --- a/lib/update.js +++ b/lib/update.js @@ -69,7 +69,7 @@ function update(updates, object, ...args) { const resolvedUpdates = resolveUpdates(updates, defaultedObject); if (isEmpty(resolvedUpdates)) { - return object; + return defaultedObject; } if (Array.isArray(defaultedObject)) { diff --git a/test/updeep-spec.js b/test/updeep-spec.js index 9769a91..0708466 100644 --- a/test/updeep-spec.js +++ b/test/updeep-spec.js @@ -129,4 +129,9 @@ describe('updeep', () => { result = u({ 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: {} }); + }); });