Skip to content

Commit

Permalink
Add support for non-plain objects
Browse files Browse the repository at this point in the history
Fixes #36
  • Loading branch information
aaronjensen committed Sep 15, 2015
1 parent 0d0c56b commit d2d0703
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## [unreleased]
* Fix support for Date objects and other non-plain objects (https://github.com/substantial/updeep/issues/36)

## [0.10.0]
* Add support for wildcards (`*`) to `u.updateIn`. (https://github.com/substantial/updeep/issues/27)
Expand Down
3 changes: 2 additions & 1 deletion lib/update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import wrap from './wrap';
import isEmpty from './util/isEmpty';
import defaultObject from './util/defaultObject';
import isPlainObject from 'lodash/lang/isPlainObject';

function reduce(object, callback, initialValue) {
return Object.keys(object).reduce((acc, key) => {
Expand Down Expand Up @@ -58,7 +59,7 @@ function update(updates, object, ...args) {
return updates(object, ...args);
}

if (updates === null || typeof updates !== 'object') {
if (!isPlainObject(updates)) {
return updates;
}

Expand Down
6 changes: 6 additions & 0 deletions test/updeep-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@ describe('updeep', () => {
const result = u({ a: {} }, {});
expect(result).to.eql({ a: {} });
});

it('works with date objects', () => {
const date = new Date();
const result = u({ created: date }, {});
expect(result).to.eql({ created: date });
});
});

0 comments on commit d2d0703

Please sign in to comment.