Git Product home page Git Product logo

Comments (4)

arqex avatar arqex commented on June 3, 2024

Hi @fundkis

Thanks for your thoughts, you have described the most usual problem when working with freezer.js, using a node that has been detached from the store. I completely agree that it is a problem very difficult to debug, and I have learnt to use freezer in a way that minimize the chances of getting an incoherent state like the one you describe, but I can imagine that many people suffering this issue. I will be glad to study and merge your solution.

As for the singleParent checking, and the need of not having the nodes frozen, I think I didn't understand it well, can you explain it further? The immutability of the nodes are a nice feature to make sure that the tree is updated the right way, but it's possible to disable it using mutable: true in the initialization. https://github.com/arqex/freezer#api

Also letting a node be in 2 different places in the tree is a feature, but I am not against creating an option to enforce the opposite if it's not making the library much more complex and can help to detect errors.

Thanks again for your thoughts they are really valuable :)

from freezer.

fundkis avatar fundkis commented on June 3, 2024

thank your for the answer.
I've seen that from the tests that "letting one node to be in different places" is a feature even if it is not a documented one. We don't use that feature and we think that it is in general a bad practice: we like streamable state (the one you could rebuild with a JSON.parse(JSON.stringify(state)).
if we add a singleParent option that disable this feature, then we can forbid completely to add a frozen node in the tree. For instance we can check that the whole attrs argument of the merge function (in frozen.js) does not contain any frozen node.
We can then assert as a precondition on main functions that only plain js objects can "enter" the library. This allows to detect any misuse very early.
We can certainly do without this option: the precondition may be that you can pass only nodes that are already part of the tree and having a verification code enforcing that on debug, but this is not what we've done...

from freezer.

arqex avatar arqex commented on June 3, 2024

Now I see, you meant that with the 'singleParent' option set to true, no frozen nodes could be added to the tree. Sounds fair enough to add the option, but its default value would be false to not to break any current installation.

from freezer.

fundkis avatar fundkis commented on June 3, 2024

of course. we should be backward compatible...
I will also disable by default, the whole debugging checks and even skip the whole debugging code from the bundled js file.
I'll try to submit a PR by the end of the week

from freezer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.