-
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract generation of js_code into module (#1169)
- Loading branch information
1 parent
735c434
commit aa7060f
Showing
3 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module ReactOnRails | ||
module ServerRenderingJsCode | ||
class << self | ||
def js_code_renderer | ||
@js_code_renderer ||= if ReactOnRails::Utils.react_on_rails_pro? | ||
ReactOnRailsPro::ServerRenderingJsCode | ||
else | ||
self | ||
end | ||
end | ||
|
||
def server_rendering_component_js_code( | ||
props_string: nil, | ||
rails_context: nil, | ||
redux_stores: nil, | ||
react_component_name: nil, | ||
render_options: nil | ||
) | ||
js_code_renderer.render(props_string, rails_context, redux_stores, react_component_name, render_options) | ||
end | ||
|
||
def render(props_string, rails_context, redux_stores, react_component_name, render_options) | ||
<<-JS | ||
(function() { | ||
var railsContext = #{rails_context}; | ||
#{redux_stores} | ||
var props = #{props_string}; | ||
return ReactOnRails.serverRenderReactComponent({ | ||
name: '#{react_component_name}', | ||
domNodeId: '#{render_options.dom_id}', | ||
props: props, | ||
trace: #{render_options.trace}, | ||
railsContext: railsContext | ||
}); | ||
})() | ||
JS | ||
end | ||
end | ||
end | ||
end |