Class: ReactOnRails::ReactComponent::RenderOptions

Inherits:
Object
  • Object
show all
Includes:
Utils::Required
Defined in:
lib/react_on_rails/react_component/render_options.rb

Constant Summary collapse

NO_PROPS =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Required

#required

Constructor Details

#initialize(react_component_name: required("react_component_name"), options: required("options")) ⇒ RenderOptions

TODO: remove the required for named params



15
16
17
18
# File 'lib/react_on_rails/react_component/render_options.rb', line 15

def initialize(react_component_name: required("react_component_name"), options: required("options"))
  @react_component_name = react_component_name.camelize
  @options = options
end

Instance Attribute Details

#react_component_nameObject (readonly)

Returns the value of attribute react_component_name.



20
21
22
# File 'lib/react_on_rails/react_component/render_options.rb', line 20

def react_component_name
  @react_component_name
end

#request_digestObject

Returns the value of attribute request_digest.



10
11
12
# File 'lib/react_on_rails/react_component/render_options.rb', line 10

def request_digest
  @request_digest
end

Instance Method Details

#auto_load_bundleObject



74
75
76
# File 'lib/react_on_rails/react_component/render_options.rb', line 74

def auto_load_bundle
  retrieve_configuration_value_for(:auto_load_bundle)
end

#client_propsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/react_on_rails/react_component/render_options.rb', line 30

def client_props
  props_extension = ReactOnRails.configuration.rendering_props_extension
  if props_extension.present?
    if props_extension.respond_to?(:adjust_props_for_client_side_hydration)
      return props_extension.adjust_props_for_client_side_hydration(react_component_name,
                                                                    props.clone)
    end

    raise ReactOnRails::Error, "ReactOnRails: your rendering_props_extension module is missing the " \
                               "required adjust_props_for_client_side_hydration method & can not be used"
  end
  props
end

#dom_idObject



48
49
50
51
52
53
54
55
56
# File 'lib/react_on_rails/react_component/render_options.rb', line 48

def dom_id
  @dom_id ||= options.fetch(:id) do
    if random_dom_id
      generate_unique_dom_id
    else
      base_dom_id
    end
  end
end

#html_optionsObject



66
67
68
# File 'lib/react_on_rails/react_component/render_options.rb', line 66

def html_options
  options[:html_options].to_h
end

#internal_option(key) ⇒ Object



98
99
100
# File 'lib/react_on_rails/react_component/render_options.rb', line 98

def internal_option(key)
  options[key]
end

#logging_on_serverObject



90
91
92
# File 'lib/react_on_rails/react_component/render_options.rb', line 90

def logging_on_server
  retrieve_configuration_value_for(:logging_on_server)
end

#prerenderObject



70
71
72
# File 'lib/react_on_rails/react_component/render_options.rb', line 70

def prerender
  retrieve_configuration_value_for(:prerender)
end

#propsObject



26
27
28
# File 'lib/react_on_rails/react_component/render_options.rb', line 26

def props
  options.fetch(:props) { NO_PROPS }
end

#raise_on_prerender_errorObject



86
87
88
# File 'lib/react_on_rails/react_component/render_options.rb', line 86

def raise_on_prerender_error
  retrieve_configuration_value_for(:raise_on_prerender_error)
end

#random_dom_idObject



44
45
46
# File 'lib/react_on_rails/react_component/render_options.rb', line 44

def random_dom_id
  retrieve_configuration_value_for(:random_dom_id)
end

#random_dom_id?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/react_on_rails/react_component/render_options.rb', line 58

def random_dom_id?
  return false if options[:id]

  return false unless random_dom_id

  true
end

#replay_consoleObject



82
83
84
# File 'lib/react_on_rails/react_component/render_options.rb', line 82

def replay_console
  retrieve_configuration_value_for(:replay_console)
end

#set_option(key, value) ⇒ Object



102
103
104
# File 'lib/react_on_rails/react_component/render_options.rb', line 102

def set_option(key, value)
  options[key] = value
end

#throw_js_errorsObject



22
23
24
# File 'lib/react_on_rails/react_component/render_options.rb', line 22

def throw_js_errors
  options.fetch(:throw_js_errors, false)
end

#to_sObject



94
95
96
# File 'lib/react_on_rails/react_component/render_options.rb', line 94

def to_s
  "{ react_component_name = #{react_component_name}, options = #{options}, request_digest = #{request_digest}"
end

#traceObject



78
79
80
# File 'lib/react_on_rails/react_component/render_options.rb', line 78

def trace
  retrieve_configuration_value_for(:trace)
end