Git Product home page Git Product logo

Comments (4)

arqex avatar arqex commented on June 12, 2024

Hey aktxyz

If you want to update 2 elements in something you can do

store.something.set({a:1,b:2});

Also the update methods are chainable so this will do the same, but it's less efficient since it updates the tree completely twice:

store.something
  .set(a, 1)
  .set(b, 2)
;

The first set(a,1) return the updated node to let you edit it again.

I think that transaction is a last resort mechanism, and I have found myself using it only twice in the years I've been using Freezer. You need to update the whole tree hundreds of times in the same tick to feel that there is a performance object, so if I am not doing hundreds of updates I never use it.

from freezer.

aktxyz avatar aktxyz commented on June 12, 2024

I use the 2 methods you describe quite a bit also, but there are cases where the code for the store updates are not all together, so end up having to .transact() to work.

If I do a .transact() at the root, will that apply to all children?

from freezer.

arqex avatar arqex commented on June 12, 2024

I usually organize the functions that update the state by the part of the state they update. Eg, for I would create a file, somethingReactions.js to edit what's inside of something.

In that file I use to create a helper function to make simpler run the updates something like:

// 'd' after 'domain'
var d = function (){ return freezer.get().something };

That way I rest assured that I am updating the current content of the store:

d().set('a',1);
d().set('b',2);

I think transact is not a good thing to use so lightly, because it works stopping the tree updates on that node and if I don't call run immediately after using it, I feel like I am loosing the control of what's happening. I might be doing some other updates to the store before the transaction run, without knowing that there is a transaction going on, maybe in the same store branch I am working.

That's the reason that I never use it, unless I have to make lots of updates in one node's children, and I always call run afterwards.

By the way, I am writing an article to celebrate the 1000 stars, where I try to explain how I use freezer :)

If you want to preview and share your thoughts I'll be so grateful:
https://medium.com/@arqex/7-tips-using-react-with-freezer-f4d75e363b94

from freezer.

aktxyz avatar aktxyz commented on June 12, 2024

great idea on the article, I will read it and let you know

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.