This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,24 @@ module API
156
156
alias_native :mounted? , :isMounted
157
157
alias_native :force_update! , :forceUpdate
158
158
159
+ def set_props ( prop , &block )
160
+ raise "No native ReactComponent associated" unless @native
161
+ %x{
162
+ #{ @native } .setProps(#{ prop . to_n } , function(){
163
+ #{ block . call if block }
164
+ });
165
+ }
166
+ end
167
+
168
+ def set_props! ( prop , &block )
169
+ raise "No native ReactComponent associated" unless @native
170
+ %x{
171
+ #{ @native } .replaceProps(#{ prop . to_n } , function(){
172
+ #{ block . call if block }
173
+ });
174
+ }
175
+ end
176
+
159
177
def set_state ( state , &block )
160
178
raise "No native ReactComponent associated" unless @native
161
179
%x{
Original file line number Diff line number Diff line change @@ -280,6 +280,39 @@ def render
280
280
end
281
281
end
282
282
283
+ describe "Props Updating" do
284
+ before do
285
+ stub_const 'Foo' , Class . new
286
+ Foo . class_eval do
287
+ include React ::Component
288
+ end
289
+ end
290
+
291
+ it "should support original `setProps` as method `set_props`" do
292
+ Foo . class_eval do
293
+ def render
294
+ React . create_element ( "div" ) { params [ :foo ] }
295
+ end
296
+ end
297
+
298
+ element = renderToDocument ( Foo , { foo : 10 } )
299
+ element . set_props ( foo : 20 )
300
+ expect ( element . dom_node . innerHTML ) . to eq ( '20' )
301
+ end
302
+
303
+ it "should support original `replaceProps` as method `set_props!`" do
304
+ Foo . class_eval do
305
+ def render
306
+ React . create_element ( "div" ) { params [ :foo ] ? "exist" : "null" }
307
+ end
308
+ end
309
+
310
+ element = renderToDocument ( Foo , { foo : 10 } )
311
+ element . set_props! ( bar : 20 )
312
+ expect ( element . dom_node . innerHTML ) . to eq ( 'null' )
313
+ end
314
+ end
315
+
283
316
describe "Prop validation" do
284
317
before do
285
318
stub_const 'Foo' , Class . new
You can’t perform that action at this time.
0 commit comments