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

Commit 25b8231

Browse files
committed
Readress #158
1 parent bcc36f7 commit 25b8231

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

lib/react/api.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ def self.create_element(type, properties = {}, &block)
104104
params << create_native_react_class(type)
105105
elsif React::Component::Tags::HTML_TAGS.include?(type)
106106
params << type
107-
html_tag = true
108107
elsif type.is_a? String
109108
return React::Element.new(type)
110109
else
111110
raise "#{type} not implemented"
112111
end
113112

114113
# Convert Passed in properties
115-
properties = convert_props(properties, html_tag)
114+
properties = convert_props(properties)
116115
params << properties.shallow_to_n
117116

118117
# Children Nodes
@@ -128,18 +127,14 @@ def self.clear_component_class_cache
128127
@@component_classes = {}
129128
end
130129

131-
def self.convert_props(properties, html_tag)
130+
def self.convert_props(properties)
132131
raise "Component parameters must be a hash. Instead you sent #{properties}" unless properties.is_a? Hash
133132
props = {}
134-
updated = false
135133
properties.map do |key, value|
136134
if key == "class_name" && value.is_a?(Hash)
137135
props[lower_camelize(key)] = `React.addons.classSet(#{value.to_n})`
138136
elsif key == "class"
139137
props["className"] = value
140-
elsif key == 'value' && value.nil? && html_tag
141-
updated = true
142-
props['value'] = ''
143138
elsif ["style", "dangerously_set_inner_HTML"].include? key
144139
props[lower_camelize(key)] = value.to_n
145140
elsif React::HASH_ATTRIBUTES.include?(key) && value.is_a?(Hash)

lib/react/element.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(native_element, type, properties, block)
3636

3737
def on(*event_names, &block)
3838
event_names.each { |event_name| merge_event_prop!(event_name, &block) }
39-
@native = `React.cloneElement(#{to_n}, #{properties.to_n})`
39+
@native = `React.cloneElement(#{to_n}, #{properties.shallow_to_n})`
4040
self
4141
end
4242

spec/react/dsl_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ def render
5656
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>')
5757
end
5858

59-
it "will pass the empty string for the value attribute" do
60-
stub_const 'Foo', Class.new
61-
Foo.class_eval do
62-
include React::Component
63-
def render
64-
INPUT(value: nil).on(:change) {}
65-
end
66-
end
67-
68-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<input value=""/>')
69-
end
70-
71-
7259
it "will pass converted props through event handlers" do
7360
stub_const 'Foo', Class.new
7461
Foo.class_eval do

spec/react/element_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
end
2020
end
2121

22+
describe "Event Subscription" do
23+
it "keeps the original params" do
24+
stub_const 'Foo', Class.new
25+
Foo.class_eval do
26+
include React::Component
27+
def render
28+
INPUT(value: nil, type: 'text').on(:change) {}
29+
end
30+
end
31+
32+
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<input type="text" value=""/>')
33+
end
34+
end
35+
2236
describe 'Component Event Subscription' do
2337

2438
it 'will subscribe to a component event param' do

0 commit comments

Comments
 (0)