From 4f06d3c0a5b3f80dab6cc0f5b298967351861283 Mon Sep 17 00:00:00 2001 From: Damien Lebrun Date: Fri, 23 Dec 2016 01:19:39 +0000 Subject: [PATCH] Preserve parent nodes when removing data Fix #108 --- lib/database/store.js | 8 -------- test/spec/lib/database/store.js | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/database/store.js b/lib/database/store.js index c9249aa..4abbac5 100644 --- a/lib/database/store.js +++ b/lib/database/store.js @@ -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 => { diff --git a/test/spec/lib/database/store.js b/test/spec/lib/database/store.js index 0aaa04f..eda2589 100644 --- a/test/spec/lib/database/store.js +++ b/test/spec/lib/database/store.js @@ -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() {