Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Javier Marquez
    @arqex
    Totally agree, all that boilerplate code makes me feel like programming java instead of javascript :D
    Rahat Ahmed
    @rahatarmanahmed
    Anyone have tips for passing down a freezer object thru components?
    Context sounds like a good idea but I think you can't optimize shouldComponentUpdate with it? (correct me if wrong)
    I'm using react-router, and so I can't pass props from parent routes to children... How bad is it to just import a global State in each component instead of passing it down?
    Javier Marquez
    @arqex
    @rahatarmanahmed Sorry to reply late, I had a long nice holidays :)
    Have you had a look at this? https://www.npmjs.com/package/react-freezer-js
    It is a nice package that pass freezer's state down using the context
    Ghost
    @ghost~567889a716b6c7089cbfce6b
    Just reporting back that I've used this in a couple projects now and it is great. Eliminated exactly the code I anticipated and has left my components easier to understand and update.
    Javier Marquez
    @arqex
    Thanks @schwiet for the kind words, I am also using it in my projects (some of them really needs a performant solution!) and it works really well. It's a pity that the project can't grasp more attention. I would need to promote it better, if I just had time to do so....
    Randall Harmon
    @rjharmon
    I'd come across a blog post, or so I'd thought, mentioning that anything can be stored in the freezer. But I'm not able to find it again now. The post was referring to storing backbone models there, as I recall. Am I misremembering?
    Randall Harmon
    @rjharmon
    If I make q = { q: 3 } and store in the freezer at /myThing, and then store { r: q } in /myThing also, this plain object is two different objects in the freezer; setting /myThing.q = 4 does not change /myThing/r/q
    However, if I make a JS class and instantiate it, and use that instance in place of q, then I get a different result:
    1. cannot getListener() on this class-y object
    1. changing the class-y object at /myThing.q does modify /myThing/r/q
    ^ shoulda been # 2
    Randall Harmon
    @rjharmon
    My takeaway is that arbitrary objects can be stored as references in the freezer, but they are treated as object-id's. Only when the freezer container where they are stored is modified (say, replacing /myThing.r.q with a different object), will any changes be triggered (myThing.r.getListener() will see a change of its 'q' entry from <my-class-y-thing> to some-other-object)
    Does that sound accurate @arqex ?
    Javier Marquez
    @arqex
    Hi @fjharmon
    freezer can store reference to other freezer nodes
    but any plain object/array that you want to store will be transformed in an freezer node one
    freezer nodes are immutable and also have custom method to update the freezer store, that's why it copies everything that is added
    ..everything but a freezer node
    you can do
    var f = new Freezer({myThing:{q:{q:3}}})
    and then copy the freezer node
    Javier Marquez
    @arqex
    var state = f.get();
    f.myThing.set({r: state.myThing.q})
    Then any change in myThing.q or myThing.r will change the other and trigger an update event in the listener
    Randall Harmon
    @rjharmon
    Good clarification @arqex - thanks
    Sergei Egorov
    @bsideup

    Hey everyone

    I'm having an app where I poll whole state (API is already provided, can't change it :( ) every second, and I want to use Freezer to figure our what was really changed and how should I react (funny, I use React for render :) )

    Can somebody point me at some examples or documentation of state merging?

    Randall Harmon
    @rjharmon
    @arqex I'd like to have the freezer.get() be automatically transact()'d, so that all the updates that may happen in the store during an action (e.g. app setup or user-triggered activity) are accumulated in the resulting tree, then committed on next tick, instead of producing multiple tree states. I expect I can manually arrange that in my code, but it seems like a valuable bit of function for the freezer itself. Thoughts?
    In this example, my test with --> shows that the new state (store.get() after run()) is not the same object as transact() is, which I'd have hoped was true.
    Randall Harmon
    @rjharmon
    Here's another one that might be related: transact() returns an object that can't set() - so freezer.get().transact().set("e", 42") fails with "..set is not a function"
    @arqex is that intentional?
    YPCrumble
    @YPCrumble

    @arqex I'm testing the following code on the JSBin:

    var test = store.get();
    test.set({updateOne: "first update"}); // returns an updated state appropriately.
    test.set({updateTwo: "second update"}); // weird - does not include first update.
    store.get(); // weird - this includes updateOne but not updateTwo

    Is it desired behavior that you can only use set() on test in this example one time? Is this what pivot is for/am I missing something?

    Randall Harmon
    @rjharmon
    @YPCrumble I can't really speak about the behavior that's "desired", but set() returns the replacement node, in which updateOne was applies.
    After that, the freezer stops watching the old tree for change, and watches the new tree instead. That's why updateTwo appears to go missing. In fact if you set tree2 = test.set(...updateOne...), and then call set(...updateTwo...) on tree2, you'll see both updates in store.get() at the end
    Hope that helps @YPCrumble
    alternatively, you can say store.get().set(...update1...) and store.get().set(...update2...)
    also, pivot() can be used, yes
    Javier Marquez
    @arqex
    New updates on freezer! With the latest v0.11.0 it is possible to store class instances inside a freezer's store. They will be handled as leave values by default :#
    YPCrumble
    @YPCrumble
    @rjharmon thanks, very helpful!
    Javier Marquez
    @arqex
    :)
    Randall Harmon
    @rjharmon
    leaf values @arqex ?
    such that nested data structures in by own-properties will be mutable and their changes not tracked
    Bernd Wessels
    @BerndWessels
    Hi, I can't figure out how object references can be preserved between states. Can you have a look at this issue please arqex/freezer#77
    Javier Marquez
    @arqex
    @BerndWessels in a fast look at your code I can see these lines as problematic ones
    state.app.human.set(0, {firstName: 'Bernd'}); state.app.dog.set(99, {name: 'Brutus'});
    See that when you set the first property to the human attribute, you are creating a new state inside your store
    so state is not longer the source of true, since after that set, state!== store.get()
    so the second set can be problematic
    In this particular case dog should be the same in state and store.get
    I'll have a deeper look at the issue when I finish working, and reply to you in github