Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Hans Fjällemark
    @hfjallemark

    import Freezer from 'freezer-js'

    const freezer = new Freezer({
    arr: 1,
    })

    freezer.get().arr.push(50)

    import Freezer from 'freezer-js'
    
    const freezer = new Freezer({
      arr: [1],
    })
    
    freezer.get().arr.push(50)
    And I'm getting the following error: Uncaught TypeError: Can't add property 1, object is not extensible
    Any ideas @arqex ? I'm using Babel
    The weird thing is that it works in jsbin: http://jsbin.com/yehewezova/edit?js,console
    Same version of Freezer
    Javier Marquez
    @arqex
    Hi @hfjallemark I will need to have a deep look at it
    the error is raising when using the pushmethod?
    Hans Fjällemark
    @hfjallemark
    Yeah
    Javier Marquez
    @arqex
    Is it possible than const keyword doesn't work in the same way for babel and Node.js?
    or V8?
    my tests are passing ok
    I can't reproduce it, are you using webpack and babel loader?
    Hans Fjällemark
    @hfjallemark
    Yes -- using webpack and babel loader.
    Hans Fjällemark
    @hfjallemark
    I think I've isolated the issue -- when I remove spec.protoToAssign it works.
    Ghost
    @ghost~567889a716b6c7089cbfce6b
    just stumbled across freezer. Really elegant API! On the outset it looks like it could eliminate a lot of Store/Action code in my React app. However, I am having trouble getting an idea of what the main performance implications of your implementation might be; particularly, in regard to updates. I'm not looking for anything that claims to be lightning fast, but was hoping to get a general idea of what considerations should be made. Thanks!
    Javier Marquez
    @arqex
    Hi @schwiet , I'm glad you liked the API. I've been using freezer for a while, even in complex UI projects like a svg editor that needs to update a lot of stuff on every user interaction, and Freezer has never been a performance problem
    Even if you are using pure React components, you will save a lot of React re-rendering checks if you add the shouldComponentUpdatemethod.
    Ghost
    @ghost~567889a716b6c7089cbfce6b
    thanks for the reply. I think I'll give it a try. By far, my least favorite thing about writing a React app has been all the boiler plate code involved when I need a component to update a value. I need to add a constant event name, create and action that uses that event and has the appropriate parameters, handle the action in my store, traverse the object in the store to find the place to update. You have abstracted all of that in a more elegant way than any of the other immutable libraries I have found have. good work!
    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?