Class: ReactOnRails::RenderRequest
- Inherits:
-
Object
- Object
- ReactOnRails::RenderRequest
- Defined in:
- lib/react_on_rails/render_request.rb
Overview
Structured data object encapsulating everything needed for a server render. Replaces the ad-hoc parameter passing of js_code strings and render_options through the delegation chain.
Part of the strategy pattern refactoring (see issue #2905). Currently additive — not yet wired into the main rendering path.
Instance Attribute Summary collapse
-
#component_name ⇒ Object
readonly
Returns the value of attribute component_name.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#rails_context ⇒ Object
readonly
Returns the value of attribute rails_context.
-
#render_options ⇒ Object
readonly
Returns the value of attribute render_options.
-
#store_initializations ⇒ Object
readonly
Returns the value of attribute store_initializations.
Instance Method Summary collapse
- #dom_id ⇒ Object
-
#initialize(component_name:, props:, rails_context:, store_initializations:, render_options:) ⇒ RenderRequest
constructor
A new instance of RenderRequest.
-
#props_string ⇒ Object
Returns props as a JSON string, with unicode line/paragraph separators escaped for safe embedding in JavaScript.
- #rails_context_json ⇒ Object
- #rsc_payload_streaming? ⇒ Boolean
- #streaming? ⇒ Boolean
-
#to_js ⇒ Object
Serialize to JS code via configured builder.
Constructor Details
#initialize(component_name:, props:, rails_context:, store_initializations:, render_options:) ⇒ RenderRequest
Returns a new instance of RenderRequest.
19 20 21 22 23 24 25 |
# File 'lib/react_on_rails/render_request.rb', line 19 def initialize(component_name:, props:, rails_context:, store_initializations:, render_options:) @component_name = component_name @props = props @rails_context = rails_context @store_initializations = store_initializations @render_options = end |
Instance Attribute Details
#component_name ⇒ Object (readonly)
Returns the value of attribute component_name.
11 12 13 |
# File 'lib/react_on_rails/render_request.rb', line 11 def component_name @component_name end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
11 12 13 |
# File 'lib/react_on_rails/render_request.rb', line 11 def props @props end |
#rails_context ⇒ Object (readonly)
Returns the value of attribute rails_context.
11 12 13 |
# File 'lib/react_on_rails/render_request.rb', line 11 def rails_context @rails_context end |
#render_options ⇒ Object (readonly)
Returns the value of attribute render_options.
11 12 13 |
# File 'lib/react_on_rails/render_request.rb', line 11 def @render_options end |
#store_initializations ⇒ Object (readonly)
Returns the value of attribute store_initializations.
11 12 13 |
# File 'lib/react_on_rails/render_request.rb', line 11 def store_initializations @store_initializations end |
Instance Method Details
#dom_id ⇒ Object
47 48 49 |
# File 'lib/react_on_rails/render_request.rb', line 47 def dom_id .dom_id end |
#props_string ⇒ Object
Returns props as a JSON string, with unicode line/paragraph separators escaped for safe embedding in JavaScript.
36 37 38 39 |
# File 'lib/react_on_rails/render_request.rb', line 36 def props_string json = props.is_a?(String) ? props : props.to_json json.gsub("\u2028", '\u2028').gsub("\u2029", '\u2029') end |
#rails_context_json ⇒ Object
41 42 43 44 45 |
# File 'lib/react_on_rails/render_request.rb', line 41 def rails_context_json raise ArgumentError, "rails_context must be a Hash, got #{rails_context.class}" unless rails_context.is_a?(Hash) rails_context.to_json.gsub("\u2028", '\u2028').gsub("\u2029", '\u2029') end |
#rsc_payload_streaming? ⇒ Boolean
55 56 57 |
# File 'lib/react_on_rails/render_request.rb', line 55 def rsc_payload_streaming? .rsc_payload_streaming? end |
#streaming? ⇒ Boolean
51 52 53 |
# File 'lib/react_on_rails/render_request.rb', line 51 def streaming? .streaming? end |
#to_js ⇒ Object
Serialize to JS code via configured builder. Raises if server_bundle_js_file is not configured when prerender is true.
29 30 31 32 |
# File 'lib/react_on_rails/render_request.rb', line 29 def to_js validate_server_bundle_configured! ReactOnRails.js_code_builder.build(self) end |