File tree 4 files changed +8
-7
lines changed 4 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module ControllerLifecycle
7
7
# use old names to support Rails 3
8
8
before_filter :setup_react_component_helper
9
9
after_filter :teardown_react_component_helper
10
+ attr_reader :__react_component_helper
10
11
end
11
12
12
13
def setup_react_component_helper
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ class React::Rails::ControllerRenderer
5
5
6
6
attr_accessor :output_buffer
7
7
8
- attr_reader :request
9
8
def initialize ( options = { } )
10
- @request = options [ :request ]
9
+ controller = options [ :controller ]
10
+ @__react_component_helper = controller . __react_component_helper
11
11
end
12
12
13
13
def call ( name , options , &block )
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ class Railtie < ::Rails::Railtie
43
43
44
44
initializer "react_rails.add_component_renderer" , group : :all do |app |
45
45
ActionController ::Renderers . add :component do |component_name , options |
46
- renderer = ::React ::Rails ::ControllerRenderer . new ( request : request )
46
+ renderer = ::React ::Rails ::ControllerRenderer . new ( controller : self )
47
47
html = renderer . call ( component_name , options )
48
48
render_options = options . merge ( inline : html )
49
49
render ( render_options )
Original file line number Diff line number Diff line change @@ -34,22 +34,22 @@ def teardown
34
34
35
35
test "it creates a helper object and puts it in the request env" do
36
36
get '/pages/1'
37
- helper_obj = controller . instance_variable_get ( :@ __react_component_helper)
37
+ helper_obj = controller . __react_component_helper
38
38
assert ( helper_obj . is_a? ( DummyHelperImplementation ) , "It uses the view helper implementation class" )
39
39
end
40
40
41
41
test "it calls setup and teardown methods" do
42
42
get '/pages/1?param_test=123'
43
- helper_obj = controller . instance_variable_get ( :@ __react_component_helper)
43
+ helper_obj = controller . __react_component_helper
44
44
lifecycle_steps = [ "123" , :react_component , :teardown ]
45
45
assert_equal ( lifecycle_steps , helper_obj . events )
46
46
end
47
47
48
48
test "there's a new helper object for every request" do
49
49
get '/pages/1'
50
- first_helper = controller . instance_variable_get ( :@ __react_component_helper)
50
+ first_helper = controller . __react_component_helper
51
51
get '/pages/1'
52
- second_helper = controller . instance_variable_get ( :@ __react_component_helper)
52
+ second_helper = controller . __react_component_helper
53
53
assert ( first_helper != second_helper , "The helper for the second request is brand new" )
54
54
end
55
55
end
You can’t perform that action at this time.
0 commit comments