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
    Testing the room :)
    Welcome, I will try to ask any questions about freezer here. If I am not online, just leave it here and i'll ping back ASAP
    Vitaly
    @vitalybe
    Hey
    A design question - Wouldn't it be useful if freezer object threw an error if someone tries to mutate it?
    Currently it just ignores it
    Javier Marquez
    @arqex
    Hi @vitalybe
    Error handling of mutating a frozen object is not handled by Freezer, but the browser (or node) itself.
    If you work on strict mode in your scripts it should throw a TypeError, otherwise it will fail silently
    Vitaly
    @vitalybe
    I see what you mean, thank you!
    Rahat Ahmed
    @rahatarmanahmed
    @arqex So how does freezer work with large arrays? If I push a new element onto a large array in freezer, I should get a new reference back. Does that mean that array was copied?
    Javier Marquez
    @arqex
    Yes, the returning array is a new array with the same elements than the previous array plus the one you pushed.
    Rahat Ahmed
    @rahatarmanahmed
    @arqex probably a dumb question but is there a good way to prevent some objects in the Freezer from being frozen? Like if I wanted to store a reference to a complex type of object like a Promise or something?
    Rahat Ahmed
    @rahatarmanahmed
    Also I'm a bit confused on the warning against using transact() to update child nodes
    Rahat Ahmed
    @rahatarmanahmed
    What I understand is that child nodes won't have updated values until they grab the latest reference from freezer.get()? Is that not the point?
    Javier Marquez
    @arqex
    Hi @rahatarmanahmed . Freezer can't have not immutable data in it, having it would be a problem because those mutations wouldn't trigger update events and you wouldn't lose the control of your app.
    In cases like this I store in the freezer store the data to recreate the object I need. If I need to store a React component, for example, I put in freezer an object like {type: 'div', props:{ ... }} and reconstruct the object in every re render
    If you need some other object that can't be re-created, you need to keep it outside of freezer and be careful to track the state changes in that object, in order to have your UI always sychronized with it.
    Javier Marquez
    @arqex
    As for the transact, it holds the creation of immutable objects until run is called or until next tick
    so if you have store = new Freezer({obj: {child: {x: 1}}})
    and you do store.get().obj.transact(); any change in child nodes won't be available immediately
    store.get().obj.transact();
    store.get().obj.child.set({x:2});
    store.get().obj.child.x; // 1
    in the node you apply transactthere is no problem because you know that it is transacting
    Javier Marquez
    @arqex
    but if child is passed as prop for a component and you called obj.transact() you will find that applying updates to child won't work
    so it is recommended to use runevery time that transactis used
    and only use transact to make really big chunks of changes, otherwise freezer could handle them fast enough to not even notice that there has been multiple changes
    Hans Fjällemark
    @hfjallemark
    I am running in to a strange scenario, looks like my array inside Freezer gets frozen, this is my test code:

    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