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

Commit 0907f2a

Browse files
committed
#to_n already done the magic
1 parent 1fbaf50 commit 0907f2a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/react/api.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@ def self.create_element(type, properties = {}, &block)
5959
end
6060

6161
# Passed in properties
62-
props = `{}`
62+
props = {}
6363
properties.map do |key, value|
6464
if key == "class_name" && value.is_a?(Hash)
65-
`props[#{lower_camelize(key)}] = React.addons.classSet(#{value.to_n})`
65+
props[lower_camelize(key)] = `React.addons.classSet(#{value.to_n})`
6666
else
67-
`props[#{lower_camelize(key)}] = #{value}`
67+
props[lower_camelize(key)] = value
6868
end
6969
end
7070
params << props
7171

7272
# Children Nodes
7373
if block_given?
7474
children = [yield].flatten.each do |ele|
75-
params << ele.to_n
75+
params << ele
7676
end
7777
end
7878

79-
return React::Element.new(`React.createElement.apply(null, #{params})`)
79+
return React::Element.new(`React.createElement.apply(null, #{params.to_n})`)
8080
end
8181

8282
def self.clear_component_class_cache

spec/component_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ def render
254254
element = renderToDocument(Foo, prop: "foobar")
255255
expect(element.getDOMNode.textContent).to eq("foobar")
256256
end
257+
258+
it "should access nested params as orignal Ruby object" do
259+
Foo.class_eval do
260+
def render
261+
React.create_element("div") { params[:prop][:foo] }
262+
end
263+
end
264+
265+
element = renderToDocument(Foo, prop: {foo: 10})
266+
expect(element.getDOMNode.textContent).to eq("10")
267+
end
257268
end
258269

259270
describe "Prop validation" do

0 commit comments

Comments
 (0)