Skip to content

Commit

Permalink
Change $unset prop values (#4)
Browse files Browse the repository at this point in the history
* Changing the unset prop value for intuitive diff

* Tests are passing
  • Loading branch information
nigelgilbert authored and eivindfjeldstad committed Feb 13, 2018
1 parent a33c18e commit ec64d8b
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function set (query, field, val) {

function unset (query, field) {
query['$unset'] = query['$unset'] || {};
query['$unset'][field] = 1;
query['$unset'][field] = '';
};

/**
Expand All @@ -95,4 +95,4 @@ function join (key, prefix) {
return prefix
? prefix + '.' + key
: key;
}
}
162 changes: 162 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('query()', function () {

it('should $unset null-ish keys', function () {
var query = diff({ a: 1 }, { a: null });
assert(query.$unset.a == 1);
assert(query.$unset.a == '');
assert(!('$set' in query));
});

Expand All @@ -23,7 +23,7 @@ describe('query()', function () {
it('should work with nested keys', function () {
var query = diff({ a: { b: 1, c: 2 }}, { a: { b: 2, c: null }});
assert(query.$set['a.b'] == 2);
assert(query.$unset['a.c'] == 1);
assert(query.$unset['a.c'] == '');
});

describe('when given a filter', function () {
Expand Down

0 comments on commit ec64d8b

Please sign in to comment.