@@ -195,25 +195,55 @@ def render
195195 expect ( `window.dummy_log` ) . to eq ( [ "Warning: Failed propType: In component `Foo`\n Provided prop `foo` could not be converted to BazWoggle" ] )
196196 end
197197
198- it "can will only convert once" do
199- stub_const "BazWoggle" , Class . new
200- BazWoggle . class_eval do
201- def initialize ( kind )
202- @kind = kind
198+ describe "converts params only once" do
199+
200+ it "not on every access" do
201+ stub_const "BazWoggle" , Class . new
202+ BazWoggle . class_eval do
203+ def initialize ( kind )
204+ @kind = kind
205+ end
206+ attr_accessor :kind
207+ def self . _react_param_conversion ( json , validate_only )
208+ new ( json [ :bazwoggle ] ) if json [ :bazwoggle ]
209+ end
203210 end
204- attr_accessor :kind
205- def self . _react_param_conversion ( json , validate_only )
206- new ( json [ :bazwoggle ] ) if json [ :bazwoggle ]
211+ Foo . class_eval do
212+ param :foo , type : BazWoggle
213+ def render
214+ params . foo . kind = params . foo . kind +1
215+ "#{ params . foo . kind } "
216+ end
207217 end
218+ expect ( React . render_to_static_markup ( React . create_element ( Foo , foo : { bazwoggle : 1 } ) ) ) . to eq ( '<span>2</span>' )
208219 end
209- Foo . class_eval do
210- param :foo , type : BazWoggle
211- def render
212- params . foo . kind = params . foo . kind +1
213- "#{ params . foo . kind } "
220+
221+ it "not after state update" do
222+ stub_const "BazWoggle" , Class . new
223+ BazWoggle . class_eval do
224+ def initialize ( kind )
225+ @kind = kind
226+ end
227+ attr_accessor :kind
228+ def self . _react_param_conversion ( json , validate_only )
229+ new ( json [ :bazwoggle ] ) if json [ :bazwoggle ]
230+ end
231+ end
232+ Foo . class_eval do
233+ param :foo , type : BazWoggle
234+ export_state :change_me
235+ before_mount do
236+ params . foo . kind = params . foo . kind +1
237+ end
238+ def render
239+ "#{ params . foo . kind } - #{ Foo . change_me } "
240+ end
214241 end
242+ div = `document.createElement("div")`
243+ React . render ( React . create_element ( Foo , foo : { bazwoggle : 1 } ) , div )
244+ Foo . change_me! "updated"
245+ expect ( `div.children[0].innerHTML` ) . to eq ( "2 - updated" )
215246 end
216- expect ( React . render_to_static_markup ( React . create_element ( Foo , foo : { bazwoggle : 1 } ) ) ) . to eq ( '<span>2</span>' )
217247 end
218248
219249 it "will alias a Proc type param" do
0 commit comments