-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
native param conversions #127
Comments
@fkchang had this comment which triggered this issue: I suspect this might be related to that issue u reported on the opal gitter -- but I'm wondering the right way to handle Hashes, and more particular nested data structures that have hashes in them. Since we write react.rb components in Ruby/Opal, I expect them to handle Hashes, the problem is that while I can always pass them Opal Hashes when called from opal, say parent passing in params, using react_component() for example, passes raw JS objects, where are not compatible. In some cases I preconvert JS objects, for example in a websocket handler, other cases I change the component to convert params, but all of those feel kind of hacky. Thoughts? |
Something to throw into this, that data structures nested > 1 level deep could be an issue. I wrote a converter to convert array of javascript objects into arrays of hashes, but I have data that's arrays of hashes, which might contain arrays of hashes etc. You get to where you need to know the data structure exactly. Maybe we could just do a JSON.parse of the string interpretation of the params or something |
Maybe if type is Native as in That way your param is always a valid ruby object. |
Hang on... thinking: If you declare and you pass a native object, then we should serialize-deserialize the object. If you declare the type to be an array, then we check each element to see if it is a native object, and apply the above rule. I believe everything else converts okay automatically. Note that we already have an implementation that allows you to specify serializers for your own classes.. So if you declare the type to be some class, and that class has a convertor, and the incoming param is native object the convertor will be called. Reactive-Record uses this to convert from native objects back into active record models. The current way of specifying the conversion methods needs to be reworked (see #96) |
This issue was moved to ruby-hyperloop/hyper-react#127 |
what should happen if native objects are passed to react.rb components?
Currently we do nothing UNLESS you explicitly declare the type of the param, AND that type class has an associated react conversion method.
We've got lots of options here to discuss.
The text was updated successfully, but these errors were encountered: