Class: React::ServerRendering::ExecJSRenderer
- Inherits:
-
Object
- Object
- React::ServerRendering::ExecJSRenderer
- Defined in:
- lib/react/server_rendering/exec_js_renderer.rb
Overview
A bare-bones renderer for React.js + Exec.js
-
Depends on global ReactDOMServer in the ExecJS context
-
No Rails dependency
-
No browser concerns
Direct Known Subclasses
Constant Summary collapse
- GLOBAL_WRAPPER =
Handle Node.js & other ExecJS contexts
<<-JS var global = global || this; var self = self || this; JS
Instance Attribute Summary collapse
-
#context ⇒ ExecJS::Runtime::Context
readonly
The JS context for this renderer.
Instance Method Summary collapse
- #after_render(component_name, props, prerender_options) ⇒ Object
-
#before_render(component_name, props, prerender_options) ⇒ Object
Hooks for inserting JS before/after rendering.
-
#initialize(options = {}) ⇒ ExecJSRenderer
constructor
A new instance of ExecJSRenderer.
- #render(component_name, props, prerender_options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ExecJSRenderer
Returns a new instance of ExecJSRenderer.
11 12 13 14 |
# File 'lib/react/server_rendering/exec_js_renderer.rb', line 11 def initialize(={}) js_code = [:code] || raise('Pass `code:` option to instantiate a JS context!') @context = ExecJS.compile(GLOBAL_WRAPPER + js_code) end |
Instance Attribute Details
#context ⇒ ExecJS::Runtime::Context (readonly)
Returns The JS context for this renderer.
9 10 11 |
# File 'lib/react/server_rendering/exec_js_renderer.rb', line 9 def context @context end |
Instance Method Details
#after_render(component_name, props, prerender_options) ⇒ Object
27 |
# File 'lib/react/server_rendering/exec_js_renderer.rb', line 27 def after_render(component_name, props, ); ''; end |
#before_render(component_name, props, prerender_options) ⇒ Object
Hooks for inserting JS before/after rendering
26 |
# File 'lib/react/server_rendering/exec_js_renderer.rb', line 26 def before_render(component_name, props, ); ''; end |
#render(component_name, props, prerender_options) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/react/server_rendering/exec_js_renderer.rb', line 16 def render(component_name, props, ) js_executed_before = before_render(component_name, props, ) js_executed_after = after_render(component_name, props, ) js_main_section = main_render(component_name, props, ) render_from_parts(js_executed_before, js_main_section, js_executed_after) rescue ExecJS::ProgramError => err raise React::ServerRendering::PrerenderError.new(component_name, props, err) end |