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:
2626
2727### Fixed
2828
29+ - ` Element#render ` trigger unnecessary re-mounts when called multiple times. (#170 )
2930- Gets rid of react warnings about updating state during render (#155 )
3031- Multiple HAML classes (i.e. div.foo.bar) was not working (regression introduced in 0.8.8)
3132- 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)
119119 end
120120
121121 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`
123126 klass . class_eval do
124127 render ( container , params , &block )
125128 end
126- React . render ( React . create_element ( klass ) , self )
129+
130+ React . render ( React . create_element ( `#{ self . to_n } ._reactrb_component_class` ) , self )
127131 end
128132end if Object . const_defined? ( 'Element' )
Original file line number Diff line number Diff line change 66 React ::API . clear_component_class_cache
77 end
88
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+
930 it 'renders a top level component using render with a block' do
1031 stub_const 'Foo' , Class . new ( React ::Component ::Base )
1132 Foo . class_eval do
You can’t perform that action at this time.
0 commit comments