Skip to content

Commit e5c16de

Browse files
committed
All of these specs now pass
1 parent a04940a commit e5c16de

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: lib/react/opal/native_element.rb

+26
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,31 @@ def initialize(native)
1919
def element_type
2020
self.JS[:type]
2121
end
22+
23+
def on(event_name)
24+
name = event_name.to_s.camelize
25+
26+
prop_key = "on#{name}"
27+
28+
if React::Event::BUILT_IN_EVENTS.include?(prop_key)
29+
callback = %x{
30+
function(event){
31+
#{yield React::Event.new(`event`)}
32+
}
33+
}
34+
else
35+
callback = %x{
36+
function(){
37+
#{yield *Array(`arguments`)}
38+
}
39+
}
40+
end
41+
42+
new_prop = `{}`
43+
`new_prop[prop_key] = #{callback}`
44+
45+
cloned = `React.cloneElement(#{self}, #{new_prop})`
46+
React::NativeElement.new cloned
47+
end
2248
end
2349
end

0 commit comments

Comments
 (0)