Skip to content

Commit ec64d8b

Browse files
nigelgilberteivindfjeldstad
authored andcommitted
Change $unset prop values (#4)
* Changing the unset prop value for intuitive diff * Tests are passing
1 parent a33c18e commit ec64d8b

File tree

3 files changed

+166
-4
lines changed

3 files changed

+166
-4
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function set (query, field, val) {
8484

8585
function unset (query, field) {
8686
query['$unset'] = query['$unset'] || {};
87-
query['$unset'][field] = 1;
87+
query['$unset'][field] = '';
8888
};
8989

9090
/**
@@ -95,4 +95,4 @@ function join (key, prefix) {
9595
return prefix
9696
? prefix + '.' + key
9797
: key;
98-
}
98+
}

package-lock.json

Lines changed: 162 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('query()', function () {
1010

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

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

2929
describe('when given a filter', function () {

0 commit comments

Comments
 (0)