module React::Component

Public Class Methods

included(base) click to toggle source
# File lib/react/opal/component.rb, line 8
def self.included(base)
  base.include(API)
  base.include(React::Callbacks)
  base.class_eval do
    class_attribute :init_state, :validator, :context_types, :child_context_types, :child_context_get
    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

Public Instance Methods

component_did_mount() click to toggle source
# File lib/react/opal/component.rb, line 46
def component_did_mount
  self.run_callback(:after_mount)
end
component_did_update(prev_props, prev_state) click to toggle source
# File lib/react/opal/component.rb, line 62
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/opal/component.rb, line 42
def component_will_mount
  self.run_callback(:before_mount)
end
component_will_receive_props(next_props) click to toggle source
# File lib/react/opal/component.rb, line 50
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/opal/component.rb, line 66
def component_will_unmount
  self.run_callback(:before_unmount)
end
component_will_update(next_props, next_state) click to toggle source
# File lib/react/opal/component.rb, line 58
def component_will_update(next_props, next_state)
  self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state))
end
context() click to toggle source
# File lib/react/opal/component.rb, line 34
def context
  Hash.new(`#{self}.context`)
end
emit(event_name, *args) click to toggle source
# File lib/react/opal/component.rb, line 38
def emit(event_name, *args)
  self.params["on_#{event_name.to_s}"].call(*args)
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/react/opal/component.rb, line 78
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/opal/component.rb, line 70
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/opal/component.rb, line 23
def params
  Hash.new(`#{self}.props`).inject({}) do |memo, (k, v)|
    memo[k.underscore] = v
    memo
  end
end
refs() click to toggle source
# File lib/react/opal/component.rb, line 30
def refs
  Hash.new(`#{self}.refs`)
end
should_component_update?(next_props, next_state) click to toggle source
# File lib/react/opal/component.rb, line 54
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
to_n() click to toggle source
# File lib/react/opal/component.rb, line 106
def to_n
  self
end