Class: React::NativeElement
- Inherits:
-
Object
- Object
- React::NativeElement
- Includes:
- PropsChildren
- Defined in:
- lib/react/opal/native_element.rb
Instance Method Summary collapse
- #element_type ⇒ Object
-
#initialize(native) ⇒ NativeElement
constructor
As of React 0.14, elements are now just plain object literals, so we can’t inherit anymore We can just set each of the properties on our object though See var ReactElement = function (type, key, ref, self, source, owner, props) in the React source.
- #on(event_name) ⇒ Object
Methods included from PropsChildren
Constructor Details
#initialize(native) ⇒ NativeElement
As of React 0.14, elements are now just plain object literals, so we can’t inherit anymore We can just set each of the properties on our object though See var ReactElement = function (type, key, ref, self, source, owner, props) in the React source
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/react/opal/native_element.rb', line 8 def initialize(native) %x{ self.$$typeof = #{native}.$$typeof; self.type = #{native}.type; self.key = #{native}.key; self.ref = #{native}.ref; self.props = #{native}.props; self._owner = #{native}._owner; self._store = #{native}._store; self._self = #{native}._self; self._source = #{native}._source; } end |
Instance Method Details
#element_type ⇒ Object
22 23 24 |
# File 'lib/react/opal/native_element.rb', line 22 def element_type self.JS[:type] end |
#on(event_name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/react/opal/native_element.rb', line 26 def on(event_name) name = event_name.to_s.camelize prop_key = "on#{name}" if React::Event::BUILT_IN_EVENTS.include?(prop_key) callback = %x{ function(event){ #{yield React::Event.new(`event`)} } } else callback = %x{ function(){ #{yield *Array(`arguments`)} } } end new_prop = `{}` `new_prop[prop_key] = #{callback}` cloned = `React.cloneElement(#{self}, #{new_prop})` React::NativeElement.new cloned end |