This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ Whitespace conventions:
26
26
27
27
### Fixed
28
28
29
+ - ` Element#render ` trigger unnecessary re-mounts when called multiple times. (#170 )
29
30
- Gets rid of react warnings about updating state during render (#155 )
30
31
- Multiple HAML classes (i.e. div.foo.bar) was not working (regression introduced in 0.8.8)
31
32
- Don't send nil (null) to form components as the value string (#157 )
Original file line number Diff line number Diff line change @@ -119,10 +119,14 @@ def self.[](selector)
119
119
end
120
120
121
121
define_method :render do |container = nil , params = { } , &block |
122
- klass = Class . new ( React ::Component ::Base )
122
+ if `#{ self . to_n } ._reactrb_component_class === undefined`
123
+ `#{ self . to_n } ._reactrb_component_class = #{ Class . new ( React ::Component ::Base ) } `
124
+ end
125
+ klass = `#{ self . to_n } ._reactrb_component_class`
123
126
klass . class_eval do
124
127
render ( container , params , &block )
125
128
end
126
- React . render ( React . create_element ( klass ) , self )
129
+
130
+ React . render ( React . create_element ( `#{ self . to_n } ._reactrb_component_class` ) , self )
127
131
end
128
132
end if Object . const_defined? ( 'Element' )
Original file line number Diff line number Diff line change 6
6
React ::API . clear_component_class_cache
7
7
end
8
8
9
+ it 'will reuse the wrapper componet class for the same Element' do
10
+ stub_const 'Foo' , Class . new ( React ::Component ::Base )
11
+ Foo . class_eval do
12
+ param :name
13
+ def render
14
+ "hello #{ params . name } "
15
+ end
16
+
17
+ def component_will_unmount
18
+
19
+ end
20
+ end
21
+
22
+ expect_any_instance_of ( Foo ) . to_not receive ( :component_will_unmount )
23
+
24
+ test_div = Element . new ( :div )
25
+ test_div . render { Foo ( name : 'fred' ) }
26
+ test_div . render { Foo ( name : 'freddy' ) }
27
+ expect ( Element [ test_div ] . find ( 'span' ) . html ) . to eq ( 'hello freddy' )
28
+ end
29
+
9
30
it 'renders a top level component using render with a block' do
10
31
stub_const 'Foo' , Class . new ( React ::Component ::Base )
11
32
Foo . class_eval do
You can’t perform that action at this time.
0 commit comments