module React::Component
Public Class Methods
included(base)
click to toggle source
# File lib/react/component.rb, line 8 def self.included(base) base.include(API) base.include(React::Callbacks) base.class_eval do class_attribute :init_state, :validator define_callback :before_mount define_callback :after_mount define_callback :before_receive_props define_callback :before_update define_callback :after_update define_callback :before_unmount end base.extend(ClassMethods) end
new(native_element)
click to toggle source
# File lib/react/component.rb, line 23 def initialize(native_element) @native = native_element end
Public Instance Methods
component_did_mount()
click to toggle source
# File lib/react/component.rb, line 48 def component_did_mount self.run_callback(:after_mount) end
component_did_update(prev_props, prev_state)
click to toggle source
# File lib/react/component.rb, line 64 def component_did_update(prev_props, prev_state) self.run_callback(:after_update, Hash.new(prev_props), Hash.new(prev_state)) end
component_will_mount()
click to toggle source
# File lib/react/component.rb, line 44 def component_will_mount self.run_callback(:before_mount) end
component_will_receive_props(next_props)
click to toggle source
# File lib/react/component.rb, line 52 def component_will_receive_props(next_props) self.run_callback(:before_receive_props, Hash.new(next_props)) end
component_will_unmount()
click to toggle source
# File lib/react/component.rb, line 68 def component_will_unmount self.run_callback(:before_unmount) end
component_will_update(next_props, next_state)
click to toggle source
# File lib/react/component.rb, line 60 def component_will_update(next_props, next_state) self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) end
emit(event_name, *args)
click to toggle source
# File lib/react/component.rb, line 40 def emit(event_name, *args) self.params["_on#{event_name.to_s.event_camelize}"].call(*args) end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/react/component.rb, line 80 def method_missing(name, *args, &block) unless (React::HTML_TAGS.include?(name) || name == 'present' || name == '_p_tag') return super end if name == "present" name = args.shift end if name == "_p_tag" name = "p" end @buffer = [] unless @buffer if block current = @buffer @buffer = [] result = block.call element = React.create_element(name, *args) { @buffer.count == 0 ? result : @buffer } @buffer = current else element = React.create_element(name, *args) end @buffer << element element end
p(*args, &block)
click to toggle source
# File lib/react/component.rb, line 72 def p(*args, &block) if block || args.count == 0 || (args.count == 1 && args.first.is_a?(Hash)) _p_tag(*args, &block) else Kernel.p(*args) end end
params()
click to toggle source
# File lib/react/component.rb, line 27 def params Hash.new(`#{@native}.props`) end
refs()
click to toggle source
# File lib/react/component.rb, line 31 def refs Hash.new(`#{@native}.refs`) end
should_component_update?(next_props, next_state)
click to toggle source
# File lib/react/component.rb, line 56 def should_component_update?(next_props, next_state) self.respond_to?(:needs_update?) ? self.needs_update?(Hash.new(next_props), Hash.new(next_state)) : true end
state()
click to toggle source
# File lib/react/component.rb, line 35 def state raise "No native ReactComponent associated" unless @native Hash.new(`#{@native}.state`) end