Class: React::Rails::ComponentMount

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
Defined in:
lib/react/rails/component_mount.rb

Overview

This is the default view helper implementation. It just inserts HTML into the DOM (see #react_component).

You can extend this class or provide your own implementation by assigning it to ‘config.react.view_helper_implementation`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeComponentMount

Returns a new instance of ComponentMount.



17
18
19
# File 'lib/react/rails/component_mount.rb', line 17

def initialize
  @cache_ids = []
end

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



13
14
15
# File 'lib/react/rails/component_mount.rb', line 13

def output_buffer
  @output_buffer
end

Instance Method Details

#react_component(name, props = {}, options = {}, &block) ⇒ Object

Render a UJS-type HTML tag annotated with data attributes, which are used by react_ujs to actually instantiate the React component on the client.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/react/rails/component_mount.rb', line 32

def react_component(name, props = {}, options = {}, &block)
  options = { tag: options } if options.is_a?(Symbol)
  props = React.camelize_props(props) if options.fetch(:camelize_props, camelize_props_switch)

  prerender_options = options[:prerender]
  block = proc { concat(prerender_component(name, props, prerender_options)) } if prerender_options

  html_options = generate_html_options(name, options, props, prerender_options)

  rendered_tag(html_options, &block)
end

#setup(controller) ⇒ Object

React::Rails::ControllerLifecycle calls these hooks You can use them in custom helper implementations



23
24
25
# File 'lib/react/rails/component_mount.rb', line 23

def setup(controller)
  @controller = controller
end

#teardown(controller) ⇒ Object



27
# File 'lib/react/rails/component_mount.rb', line 27

def teardown(controller); end