Module: React::Rails::ControllerLifecycle

Extended by:
ActiveSupport::Concern
Defined in:
lib/react/rails/controller_lifecycle.rb

Overview

This module is included into ActionController so that per-request hooks can be called in the view helper.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#per_request_react_rails_prerendererObject

If you want a per-request renderer, add this method as an around-action

(‘.per_request_react_rails_prerenderer` does this for you)

Examples:

Having one renderer instance for each controller action

around_action :per_request_react_rails_prerenderer


40
41
42
43
44
45
# File 'lib/react/rails/controller_lifecycle.rb', line 40

def per_request_react_rails_prerenderer
  React::ServerRendering.with_renderer do |renderer|
    @__react_rails_prerenderer = renderer
    yield
  end
end

#react_rails_prerendererObject

An instance of a server renderer, for use during this request



48
49
50
# File 'lib/react/rails/controller_lifecycle.rb', line 48

def react_rails_prerenderer
  @__react_rails_prerenderer
end

#use_react_component_helperObject

Instantiate the ViewHelper implementation and call its #setup method then let the controller action run, then call the ViewHelper implementation’s #teardown method



27
28
29
30
31
32
33
# File 'lib/react/rails/controller_lifecycle.rb', line 27

def use_react_component_helper
  new_helper = React::Rails::ViewHelper.helper_implementation_class.new
  new_helper.setup(self)
  @__react_component_helper = new_helper
  yield
  @__react_component_helper.teardown(self)
end