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.