Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freezer: Can't add node to the tree. It's already added and freezer is configured to singleParent: true #118

Open
djhr opened this issue Oct 1, 2020 · 0 comments

Comments

@djhr
Copy link

djhr commented Oct 1, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant