Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit a952cd2

Browse files
committed
def collected params method on proxy, closes #100
1 parent cd8150b commit a952cd2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/react/component/class_methods.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def collect_other_params_as(name)
9898
define_method(name) do
9999
@_all_others ||= self.class.validator.undefined_props(props)
100100
end
101+
102+
validator_in_lexial_scope = validator
103+
props_wrapper.define_method(name) do
104+
@_all_others ||= validator_in_lexial_scope.undefined_props(props)
105+
end
101106
end
102107

103108
def define_state(*states, &block)

spec/react/param_declaration_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
if opal?
44
describe 'the param macro' do
5+
it 'defines collect_other_params_as method on params proxy' do
6+
stub_const 'Foo', Class.new(React::Component::Base)
7+
Foo.class_eval do
8+
collect_other_params_as :foo
9+
10+
def render
11+
div { params.foo[:bar] }
12+
end
13+
end
14+
15+
html = React.render_to_static_markup(React.create_element(Foo, { bar: 'biz' }))
16+
expect(html).to eq('<div>biz</div>')
17+
end
18+
19+
it 'still defines deprecated collect_other_params_as method' do
20+
stub_const 'Foo', Class.new(React::Component::Base)
21+
Foo.class_eval do
22+
collect_other_params_as :foo
23+
24+
def render
25+
div { foo[:bar] }
26+
end
27+
end
28+
29+
html = React.render_to_static_markup(React.create_element(Foo, { bar: 'biz' }))
30+
expect(html).to eq('<div>biz</div>')
31+
end
32+
533
it 'still defines deprecated param accessor method' do
634
stub_const 'Foo', Class.new(React::Component::Base)
735
Foo.class_eval do

0 commit comments

Comments
 (0)