class React::Element
Attributes
block[R]
properties[R]
type[R]
waiting_on_resources[RW]
Public Class Methods
new(native_element, type, properties, block)
click to toggle source
# File lib/react/element.rb, line 16 def initialize(native_element, type, properties, block) @type = type @properties = (`typeof #{properties} === 'undefined'` ? nil : properties) || {} @block = block @native = native_element end
Public Instance Methods
as_node()
click to toggle source
# File lib/react/element.rb, line 69 def as_node React::RenderingContext.as_node(self) end
delete()
click to toggle source
# File lib/react/element.rb, line 73 def delete React::RenderingContext.delete(self) end
method_missing(class_name, args = {}, &new_block)
click to toggle source
# File lib/react/element.rb, line 58 def method_missing(class_name, args = {}, &new_block) class_name = class_name.split("__").collect { |s| s.gsub("_", "-") }.join("_") new_props = properties.dup new_props["class"] = "#{new_props['class']} #{class_name} #{args.delete("class")} #{args.delete('className')}".split(" ").uniq.join(" ") new_props.merge! args React::RenderingContext.replace( self, React::RenderingContext.build { React::RenderingContext.render(type, new_props, &new_block) } ) end
on(event_name)
click to toggle source
# File lib/react/element.rb, line 23 def on(event_name) name = event_name.to_s.event_camelize props = if React::Event::BUILT_IN_EVENTS.include?("on#{name}") {"on#{name}" => %x{ function(event){ #{yield React::Event.new(`event`)} } }} else {"_on#{name}" => %x{ function(){ #{yield *Array(`arguments`)} } }} end @native = `React.cloneElement(#{self.to_n}, #{props.to_n})` @properties.merge! props self end
render(props = {})
click to toggle source
# File lib/react/element.rb, line 43 def render(props = {}) # for rendering children if props.empty? React::RenderingContext.render(self) else React::RenderingContext.render( Element.new( `React.cloneElement(#{self.to_n}, #{API.convert_props(props)})`, type, properties.merge(props), block ) ) end end