File tree Expand file tree Collapse file tree 4 files changed +8
-7
lines changed Expand file tree Collapse file tree 4 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module ControllerLifecycle
77 # use old names to support Rails 3
88 before_filter :setup_react_component_helper
99 after_filter :teardown_react_component_helper
10+ attr_reader :__react_component_helper
1011 end
1112
1213 def setup_react_component_helper
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ class React::Rails::ControllerRenderer
55
66 attr_accessor :output_buffer
77
8- attr_reader :request
98 def initialize ( options = { } )
10- @request = options [ :request ]
9+ controller = options [ :controller ]
10+ @__react_component_helper = controller . __react_component_helper
1111 end
1212
1313 def call ( name , options , &block )
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ class Railtie < ::Rails::Railtie
4343
4444 initializer "react_rails.add_component_renderer" , group : :all do |app |
4545 ActionController ::Renderers . add :component do |component_name , options |
46- renderer = ::React ::Rails ::ControllerRenderer . new ( request : request )
46+ renderer = ::React ::Rails ::ControllerRenderer . new ( controller : self )
4747 html = renderer . call ( component_name , options )
4848 render_options = options . merge ( inline : html )
4949 render ( render_options )
Original file line number Diff line number Diff line change @@ -34,22 +34,22 @@ def teardown
3434
3535 test "it creates a helper object and puts it in the request env" do
3636 get '/pages/1'
37- helper_obj = controller . instance_variable_get ( :@ __react_component_helper)
37+ helper_obj = controller . __react_component_helper
3838 assert ( helper_obj . is_a? ( DummyHelperImplementation ) , "It uses the view helper implementation class" )
3939 end
4040
4141 test "it calls setup and teardown methods" do
4242 get '/pages/1?param_test=123'
43- helper_obj = controller . instance_variable_get ( :@ __react_component_helper)
43+ helper_obj = controller . __react_component_helper
4444 lifecycle_steps = [ "123" , :react_component , :teardown ]
4545 assert_equal ( lifecycle_steps , helper_obj . events )
4646 end
4747
4848 test "there's a new helper object for every request" do
4949 get '/pages/1'
50- first_helper = controller . instance_variable_get ( :@ __react_component_helper)
50+ first_helper = controller . __react_component_helper
5151 get '/pages/1'
52- second_helper = controller . instance_variable_get ( :@ __react_component_helper)
52+ second_helper = controller . __react_component_helper
5353 assert ( first_helper != second_helper , "The helper for the second request is brand new" )
5454 end
5555end
You can’t perform that action at this time.
0 commit comments