-
Notifications
You must be signed in to change notification settings - Fork 757
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
Decouple renderer #253
Decouple renderer #253
Conversation
|
||
html_options = options.reverse_merge(:data => {}) | ||
html_options[:data].tap do |data| | ||
data[:react_class] = name | ||
data[:react_props] = React::Renderer.react_props(args) unless args.empty? | ||
data[:react_props] = (props.is_a?(String) ? props : props.to_json) |
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.
This should always be JSON because ReactRailsUJS
will try to parse it as JSON!
This looks great! I'll have to check it out tomorrow and see if I can use this API to build out something from my original example in #143. |
Somehow I broke a lot of tests 😞 gotta check that out. |
+1. I would like to see a way to render with |
As an abstraction layer, I think this looks good. The direction I took my implementation, basically to support seeding Flux stores from Rails data, reuses much of the impl of Renderer. It would be nice if there were some extension points to allow that. For example: js_code = <<-JS
(function () {
#{preparation_js}
var result = React.renderToString(React.createElement(#{component_name}, #{props}));
#{post_render_js}
return result;
})()
JS
...
def preparation_js
end
def post_render_js
@replay_console ? CONSOLE_REPLAY : ""
end That way I could just subclass the Sprockets render and tweak a few things. But maybe someone more clever than me can come up with a better way to handle the whole Flux thing anyway. |
@johnthethird I made it so you can do @RearAdmiral I can jive with that, I'll do it tomorrow |
I'm stumped on this failing test -- the asset pipeline serves the right file, but the route doesn't If i start up the dummy app, it works as expected: And it passes on master, I don't know what I changed between here and there that would change asset delivery 😩 Tried:
|
Ugh, it's test order: if I remove the tests I added, everything runs ok. |
Asking for help rails/sprockets#51 |
It ain't pretty but it's working. My call to the asset pipeline in SprocketsRenderer (in an earlier test) caused I'm bummed that we have a test-order issue :S But, it's a very odd case, it only fails on old Sprockets, and the same actions work in the |
Double-checked this on a local project. Works & reloads on changes :) |
I'm happy to see this merged. This is the key foundational step for a future flux-compatible plugin gem. @rmosolgo did you ever have a chance to work on extension points for the base class? See my comment above If you haven't spent any time on it, I can try to write one and see what everyone thinks Thanks again for pushing this through. |
Shoot, I thought I did that but obviously not :S I'm definitely open to it On Fri, May 15, 2015 at 1:15 PM, Bill DePhillips notifications@github.com
|
This seems to have introduced a regression when trying to use prerender:true and already stringified properties being passed into react_component. For example, if you use jbuilder to build your JSON you could in the past(without this pull request) do something like
It seems that the changes in view_helper.rb are the culprit. view_helper.rb#L12 assumes that the props aren't already stringified. |
@mchristen thanks for reporting and finding the problem! I added some tests & worked up a fix here: #268 |
@@ -0,0 +1,6 @@ | |||
guard :minitest do |
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.
guard throws a circular loading in progress warning
This is my attempt to decouple the server renderer as described in #143 (comment)
React::ServerRendering
handles pooling & provides an interface to the rest of the gem#initialize(options)
and#render(component_name, props)
React::ServerRendering::SprocketsRenderer
is an implementation which uses files from the asset pipeline to prerender components.Whaddya think? Does this provide enough flexibility for issues like the #143?
Also I added
guard
&Guardfile
, I think it's a nice addition to the development flow, does anyone mind?