Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
Fix gcanti#170 - t.update: cannot $merge and $remove at once
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamlyus committed Jan 22, 2016
1 parent 7155d49 commit 4d0e7e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function update(instance, spec) {
for (var k in spec) {
if (spec.hasOwnProperty(k)) {
if (update.commands.hasOwnProperty(k)) {
return update.commands[k](spec[k], value);
value = update.commands[k](spec[k], value);
isChanged = true;
}
else {
var newValue = update(value[k], spec[k]);
Expand Down
12 changes: 12 additions & 0 deletions test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ describe('t.update(instance, spec)', function () {
assert.deepEqual(actual, [1, 3, 2, 4]);
});

it('can $merge and $remove at once', function () {
var instance = {a: [1, 2], b: true};
var actual = update(instance, { $merge: {a: [1, 2, 3] }, $remove: ['b'] });
assert.deepEqual(instance, {a: [1, 2], b: true});
assert.deepEqual(actual, {a: [1, 2, 3]});
});

it('should not change the reference when no changes occurs', function () {
var p1 = {x: 0, y: 1};
var p2 = update(p1, {});
Expand Down Expand Up @@ -218,6 +225,11 @@ describe('t.update(instance, spec)', function () {
var updated = update(instance, {$remove: ['a']});
assert.deepEqual(updated, {b: 2});
});

it('can $merge and $remove at once', function () {
var updated = update(instance, { $merge: {a: [1, 2, 3] }, $remove: ['b'] });
assert.deepEqual(updated, {a: [1, 2, 3]});
});

});

Expand Down

0 comments on commit 4d0e7e5

Please sign in to comment.