-
-
Notifications
You must be signed in to change notification settings - Fork 638
Allow rendering of React components without using a generator function (just direct React Component) #19
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
Conversation
app/helpers/react_on_rails_helper.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks excellent. CC: @alexfedoseev @samnang. This looks like a good way to determine if the component is a React.Component. We need to make sure this works for createClass as well as the ES6 class definition. Another option could be to check if the object has a property called render
that's a function. We also need to consider if the React API might change in ways that would break this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a good point. We need to make sure it work with React.createClass
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could confirm that it doesn't work with createClass
. http://jsbin.com/relijopuqi/edit?js,console,output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petehunt What's the best, most canonical, way to decide if we have a real React Component? (class or generated)? Something that will work as React evolves...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josiasds Let's get this wrapped up. I want to push this to rubygems ASAP! Lots of people ready to use this! 👍 :-) |
- Add support to React components generated with React.createClass() - Add “generator” property to allow creating a React component via a function - Add HelloES5 component to the dummy application
@justin808 Ready! |
lib/react_on_rails/react_renderer.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static?
def self.render_js...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change the signature so it's clear that you're not passing the real props.
def render_js_react_element(react_component_name, props_name)
- Renaming Ruby variables to snake case - Make ReactRenderer#render_js_react_element a class method - Improve generated JS code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment above this line:
# create the server generated html of the react component with props
See #20 |
Add protocol versions and scheduled workers restarts
Add protocol versions and scheduled workers restarts
When using Redux, the main component exposed to the API is a function that returns a React component. This PR allows rendering of simple React components. The more advanced functionality of using a generator function is essential for tools like redux and react-router.
In the dummy app, along with App component (that uses Redux),
ServerApp
andClientApp
now also export a simple React component, HelloWorld. The component can be rendered by the client or using server side rendering, as demonstrated in the index page.To test, run the dummy app and export some components with and without Redux, in both client an server apps.