A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k
stars
56
forks
source link
Freezer: Can't add node to the tree. It's already added and freezer is configured to `singleParent: true` #118
When running the following code freezer correctly warns about calling remove on a detached node
const data = {
a: {
aa: {},
ab: {},
ac: {},
ad: {}
},
};
const store = new Freezer(data, {singleParent: true});
const a = store.get().a;
a.remove('aa');
setTimeout(() => {
a.remove(['ab', 'ac', 'ad']);
}, 500);
WARNING: Method object.remove called on a detached node. { aa: {}, ab: {}, ac: {}, ad: {} } [ 'ab', 'ac', 'ad' ]
However if data has a property b, the exact same code will make freezer throw an error
const data = {
a: {
aa: {},
ab: {},
ac: {},
ad: {}
},
b: {},
};
const store = new Freezer(data, {singleParent: true});
const a = store.get().a;
a.remove('aa');
setTimeout(() => {
a.remove(['ab', 'ac', 'ad']);
}, 500);
/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/frozen.js:407
throw new Error("Freezer: Can't add node to the tree. It's already added and freezer is configured to `singleParent: true`.");
^
Error: Freezer: Can't add node to the tree. It's already added and freezer is configured to `singleParent: true`.
at Object.addParent (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/frozen.js:407:11)
at /Users/djhr/Desktop/freezer/node_modules/freezer-js/src/frozen.js:319:8
at Object.each (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/utils.js:44:5)
at Object.refresh (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/frozen.js:312:9)
at Object.refreshParents (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/frozen.js:385:10)
at Object.remove (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/frozen.js:164:8)
at Object.notify (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/freezer.js:72:33)
at Object.remove (/Users/djhr/Desktop/freezer/node_modules/freezer-js/src/nodeCreator.js:153:27)
at Timeout._onTimeout (/Users/djhr/Desktop/freezer/test.js:20:5)
at listOnTimeout (internal/timers.js:549:17)
I would expect freezer not to throw an error about adding nodes, code is only removing. Instead I would expect freezer to warn about the remove on a detached node.
When running the following code freezer correctly warns about calling remove on a detached node
WARNING: Method object.remove called on a detached node. { aa: {}, ab: {}, ac: {}, ad: {} } [ 'ab', 'ac', 'ad' ]
However if
data
has a propertyb
, the exact same code will make freezer throw an errorI would expect freezer not to throw an error about adding nodes, code is only removing. Instead I would expect freezer to warn about the remove on a detached node.