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

Commit c5cb6d3

Browse files
committed
closes #124
1 parent 501ce76 commit c5cb6d3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/react/component/props_wrapper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def self.define_param(name, param_type, owner)
3333
end
3434
else
3535
define_method("#{name}") do
36-
if param_type.respond_to? :_react_param_conversion
36+
@processed_params[name] ||= if param_type.respond_to? :_react_param_conversion
3737
param_type._react_param_conversion props[name]
3838
elsif param_type.is_a?(Array) &&
3939
param_type[0].respond_to?(:_react_param_conversion)
@@ -49,6 +49,7 @@ def self.define_param(name, param_type, owner)
4949

5050
def initialize(props)
5151
@props = props || {}
52+
@processed_params = {}
5253
end
5354

5455
def [](prop)

spec/react/param_declaration_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ def render
195195
expect(`window.dummy_log`).to eq(["Warning: Failed propType: In component `Foo`\nProvided 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
203+
end
204+
attr_accessor :kind
205+
def self._react_param_conversion(json, validate_only)
206+
new(json[:bazwoggle]) if json[:bazwoggle]
207+
end
208+
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}"
214+
end
215+
end
216+
expect(React.render_to_static_markup(React.create_element(Foo, foo: {bazwoggle: 1}))).to eq('<span>2</span>')
217+
end
218+
198219
it "will alias a Proc type param" do
199220
Foo.class_eval do
200221
param :foo, type: Proc

0 commit comments

Comments
 (0)