Skip to content

Commit

Permalink
Preserve parent nodes when removing data
Browse files Browse the repository at this point in the history
Fix #108
  • Loading branch information
dinoboff committed Dec 23, 2016
1 parent 52a6e97 commit 4f06d3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 0 additions & 8 deletions lib/database/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,6 @@ class DataNode {

paths.split(path).every(key => {
const siblings = Object.keys(currSrc).filter(k => k !== key);

// if the only item is the one to remove,
// abort iteration.
if (siblings.length === 0) {
return false;
}

// Or copy other items
const currDest = dest();

siblings.forEach(k => {
Expand Down
16 changes: 16 additions & 0 deletions test/spec/lib/database/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ describe('store', function() {
expect(newRoot.$value()).to.deep.equal(data.$value());
});

it('should copy parent nodes', function() {
data = store.create({
a: {
b: {
c: true,
d: true
},
e: true
}
});

const newRoot = data.$remove('a/b/c');

expect(newRoot.$value()).to.eql({a: {b: {d: true}, e: true}});
});

});

describe('#$child', function() {
Expand Down

0 comments on commit 4f06d3c

Please sign in to comment.