Skip to content
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

Open
catmando opened this issue Feb 5, 2016 · 5 comments
Open

native param conversions #127

catmando opened this issue Feb 5, 2016 · 5 comments

Comments

@catmando
Copy link
Collaborator

catmando commented Feb 5, 2016

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.

@catmando
Copy link
Collaborator Author

catmando commented Feb 5, 2016

@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?

@fkchang
Copy link
Contributor

fkchang commented Feb 5, 2016

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

@catmando
Copy link
Collaborator Author

catmando commented Feb 5, 2016

Maybe if type is Native as in param :foo, type: Native it means to convert incoming to a string, then JSON parse it, and if that fails just wrap it in Native.

That way your param is always a valid ruby object.

@catmando
Copy link
Collaborator Author

catmando commented Feb 5, 2016

Hang on... thinking:

If you declare param :foo, type: Hash

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)

@sollycatprint
Copy link

This issue was moved to ruby-hyperloop/hyper-react#127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants