Giter VIP home page Giter VIP logo

Comments (17)

tshaddix avatar tshaddix commented on May 20, 2024 1

@abhinavzspace @vhmth The way that this library works is through Chrome Message Passing. This page states:

A message can contain any valid JSON object (null, boolean, number, string, array, or object).

This is most likely your issue. At the end of the day, as your data moves between event, content-scripts, and popovers, it is being serialized with .toJSON(). This will cause Immutable objects to be turned to normal JS objects.

I think there is a way we could add configuration parameters that would allow the "immutable type" to be passed with the payload, and then have the different components parse the objects back to their expected immutable before being passed around the app.

Would essentially need configuration on ProxyStore and store wrapper that would facilitate this as data is moved between them.

from webext-redux.

vhmth avatar vhmth commented on May 20, 2024

@abhinavzspace mind posting some error traces? We should make this lib compatible with immutable

from webext-redux.

EdmundLeex avatar EdmundLeex commented on May 20, 2024

I feel like parsing the serialized object back into immutable type on the view layer seems unnecessary. What's important is just, you can use immutable type in the store (your library seems to work with Immutable.js nicely already). Then on the react view layer, just get the state as if you are getting from a normal js object. You are not mutating it anyway. Just a thought.

from webext-redux.

tshaddix avatar tshaddix commented on May 20, 2024

@EdmundLeex Great point! I completely agree with you :)

from webext-redux.

abhinavzspace avatar abhinavzspace commented on May 20, 2024

@EdmundLeex I am doing exactly the way you mentioned. 👍

from webext-redux.

abhinavzspace avatar abhinavzspace commented on May 20, 2024

Close issue button should not be too close to comment button...... :)

from webext-redux.

abhinavzspace avatar abhinavzspace commented on May 20, 2024

BTW there is no need for compatibility with immutable.js. So it's not a real issue. Please close it if you feel like.

from webext-redux.

tshaddix avatar tshaddix commented on May 20, 2024

@abhinavzspace Sounds good! Thank you :)

from webext-redux.

SudoPlz avatar SudoPlz commented on May 20, 2024

What about shouldComponentUpdate ? How do we know if an object is the same or wether it has changed (when it has a deep structure)?
That was another great reason for me to use immutable objects.

Thanks.

from webext-redux.

vhmth avatar vhmth commented on May 20, 2024

@SudoPlz that would be orthogonal to what @EdmundLeex was mentioning. If that's the case and you are afraid of mutations at the view layer in your content and popup scripts (which is something immutable says it protects against), we should probably go with the method of allowing for immutable types in a configuration option (like @tshaddix mentioned).

I would work on this, but, since we don't use immutable.js at Loom, it's hard to justify pushing this effort forward on my end vs. working on #65 (just being real). @SudoPlz or @abhinavzspace would either of y'all be interested in extending the store to allow for immutable data types?

from webext-redux.

SudoPlz avatar SudoPlz commented on May 20, 2024

Hmm, not sure if I got @tshaddix 's answer right, but it seems to me that whenever the immutable is passed as a message, it's being serialised, and the solution would be to manually create a new Immutable after we receive an object from the store.

But that would mean that we'd always have a new immutable object, and the nextProps.anImmutable !== this.props.anImmutable would always return true;

from webext-redux.

EdmundLeex avatar EdmundLeex commented on May 20, 2024

it seems to me that whenever the immutable is passed as a message, it's being serialised, and the solution would be to manually create a new Immutable after we receive an object from the store

yes, pretty much.

nextProps.anImmutable !== this.props.anImmutable shouldn't this be false if there is a difference if you just compare the serialized js object? Both would've been serialized by the time you compare them in the view layer.

from webext-redux.

vhmth avatar vhmth commented on May 20, 2024

I think @SudoPlz is correct. nextProps.anImmutable would never equal this.props.anImmutable since the entire object is always serialized. This lib doesn't currently do "patches" to the store. That seems to be the only way to get this right.

from webext-redux.

corytheboyd avatar corytheboyd commented on May 20, 2024

Bringing this issue back to life, as I am no longer able to use Immutable with this library. You cannot simply deserialize the store in the view layer with Immutable fromJS if your state uses non-standard data structures (i.e. OrderedMap). If there were hooks into where serialization happens on both ends of the sendMessage it wouldn't be hard to use something like https://github.com/glenjamin/transit-immutable-js to keep things Immutable across the stack.

from webext-redux.

vhmth avatar vhmth commented on May 20, 2024

This got landed not too long ago:

#100

Not a fix, but should make things a bit less "horrible" for those relying on immutability (although not perfect - esp. for this case).

How are OrderedMaps usually handled in Redux? Is OrderedMap typically handled/serialized ok in other Redux apps? This is a noob question, but I'm trying to get a lay of immutable.js land.

from webext-redux.

corytheboyd avatar corytheboyd commented on May 20, 2024

@vhmth Oh nice, will take a look at upgrading soon!

In your normal Redux application the Immutable OrderedMap object will retain it's shape (as in it will not be serialized before insertion into the store). This falls apart here across the chrome messaging port since it serializes complex objects. OrderedMap actually serializes to an object (which is obviously wrong, as you lose the order deserialization):

const om = new Immutable.OrderedMap([['foo', 1], ['bar', 2]])
JSON.stringify(om)
//=> "{"foo":1,"bar":2}"

from webext-redux.

vhmth avatar vhmth commented on May 20, 2024

@corytheboyd this is super late, but is this still an issue for you? I won't be able to tackle this kinda functionality, but I wanna make sure this doesn't slip through the cracks.

from webext-redux.

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.