Skip to content

Add suffix code for context during server rendering #115

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

Closed
wants to merge 1 commit into from

Conversation

azhuravlev
Copy link

Allow to send and execute js code during context compiling, before component eval.
This can be usefull, then components are using some variables generated on server, such as generated by Gon https://github.com/gazay/gon

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@rmosolgo
Copy link
Member

Interesting, why is this better than just jamming it into a <script>? for example:

<script>
  window.rubyVar = <%= @some_ruby_var.to_json %>
</script>

(My first thought is that this is beyond the scope of react-rails but I could be missing something!)

@azhuravlev
Copy link
Author

If work with Gon, it escapes variables and puts them into script, as you wrote and return only script content for more than one variable, so you can send to context more than one variable, or function and use them later in server rendered component.

@xionon
Copy link
Contributor

xionon commented Dec 9, 2014

Why would you want to do this instead of passing data in as props? It seems to me that accessing global data is very un-React-y.

@azhuravlev
Copy link
Author

  1. Passing data with prop - good idea, but if you have some global data for all components - it's not so good. In this case we should send same set of variables to many components/
  2. Jamming ruby values to context script also good idea, but in this case we should thought about namespaces and other things, that Gon do.

@xionon
Copy link
Contributor

xionon commented Dec 10, 2014

I guess I still don't understand why this belongs in the react-rails project. If you need the functionality that Gon provides, why not just use Gon? I don't see why this should be a core component for react-rails when other libraries provide the same functionality in a cleaner way.

Alternatively, if you have a single parent component, you could pass the props down from the parent to the children.

@azhuravlev
Copy link
Author

We use Gon, and can't pass any globals when render react component on server, using common functionality.
And if you have many global props, i guess it's not good idea to pass them to all children

@xionon
Copy link
Contributor

xionon commented Dec 10, 2014

I still don't see how this isn't solved by using a parent component and sharing props between children that way. It seems that using a large amount of global data within the React framework would lead to problems down the line, and a small amount could just be passed in via props.

Can you provide an example of a case where you would not want React to manage that data?

@azhuravlev
Copy link
Author

Ok, I have some components that using others, and them use global data such as user city, sales cities and some other global vars that cached and send with Gon from different places. And i haven't any global component, that can share props.
I don't want React to manage that data in parent components, because components that using global data - only small building blocks and can be used in different places.

@xionon
Copy link
Contributor

xionon commented Dec 10, 2014

This still sounds like they should be props passed in to each component. I don't understand how adding global variables to each react_component call is any different from just putting the variables in the props hash for that component. If the component is dependent on a particular piece of data to render, it really seems like that data should be passed in as a property.

@azhuravlev
Copy link
Author

I don't add globals to all components, only there they needed, and only during serverside rendering.
this is done for structure like this:
component1(no globals) -> component2(no globals) -> component3(use globals)
component4(no globals) -> component3(use globals)

I think it's not good idea to pass globals as props to component1 or 4, then render them on server

@xionon
Copy link
Contributor

xionon commented Dec 11, 2014

Maybe someone else wants to speak on this, but I think that passing those
values from component1 and component4 is exactly what you're supposed to do
in react.

Put another way, if is a parent node of , and
depends on prop userCity to render, then also
depends on prop userCity to render. It's not a global, it's a property of
that gets passed down to its children. And if a separately
rendered also has a child , then should
get the prop userCity as well.

On Thursday, December 11, 2014, Alexey Zhuravlev [email protected]
wrote:

I don't add globals to all components, only there they needed, and only
during serverside rendering.
this is done for structure like this:
component1(no globals) -> component2(no globals) -> component3(use globals)
component4(no globals) -> component3(use globals)

I think it's not good idea to pass globals as props to component1 or 4,
then render them on server


Reply to this email directly or view it on GitHub
#115 (comment).

@rmosolgo
Copy link
Member

IMO 👎 for being non-idiomatic React

@rmosolgo
Copy link
Member

Hoping to support more customization of the view helper with #346 !

That way you could distribute a custom helper & renderer in a gem and hook them up with a railtie.

@rmosolgo
Copy link
Member

I hope that new extension point is working for you!

@rmosolgo rmosolgo closed this Feb 12, 2016
@ghost ghost added the CLA signed label Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants