module Hyalite::Component
Constants
- TAGS
Attributes
context[RW]
props[RW]
refs[RW]
Public Class Methods
included(klass)
click to toggle source
# File lib/hyalite/component.rb, line 27 def self.included(klass) klass.instance_eval do define_singleton_method(:state) do |key, initial_value| (@initial_state ||= {})[key] = initial_value end define_singleton_method(:initial_state) { @initial_state || {} } define_singleton_method(:before_mount) do |&block| if block @before_mount = block else @before_mount end end define_singleton_method(:after_mount) do |&block| if block @after_mount = block else @after_mount end end define_singleton_method(:before_unmount) do |&block| if block @before_unmount = block else @before_unmount end end define_singleton_method(:after_unmount) do |&block| if block @after_unmount = block else @after_unmount end end define_singleton_method(:before_update) do |&block| if block @before_update = block else @before_update end end define_singleton_method(:after_update) do |&block| if block @after_update = block else @after_update end end end TAGS.each do |tag| define_method(tag) do |props, *children, &block| if block Hyalite.create_element_hook do |hook_setter| renderer = ChildrenRenderer.new(self, hook_setter) renderer.instance_eval(&block) children += renderer.children.select{|el| el.is_a?(ElementObject) && el.parent.nil? } end end Hyalite.create_element(tag, props, *children) end end klass.extend ClassMethods end
Public Instance Methods
child_context()
click to toggle source
# File lib/hyalite/component.rb, line 150 def child_context {} end
component_did_mount()
click to toggle source
# File lib/hyalite/component.rb, line 158 def component_did_mount self.instance_eval(&self.class.after_mount) if self.class.after_mount end
component_did_unmount()
click to toggle source
# File lib/hyalite/component.rb, line 166 def component_did_unmount self.instance_eval(&self.class.after_unmount) if self.class.after_unmount end
component_did_update(props, state, context)
click to toggle source
# File lib/hyalite/component.rb, line 174 def component_did_update(props, state, context) self.instance_exec(props, state, context, &self.class.after_update) if self.class.after_update end
component_will_mount()
click to toggle source
# File lib/hyalite/component.rb, line 154 def component_will_mount self.instance_eval(&self.class.before_mount) if self.class.before_mount end
component_will_unmount()
click to toggle source
# File lib/hyalite/component.rb, line 162 def component_will_unmount self.instance_eval(&self.class.before_unmount) if self.class.before_unmount end
component_will_update(props, state, context)
click to toggle source
# File lib/hyalite/component.rb, line 170 def component_will_update(props, state, context) self.instance_exec(props, state, context, &self.class.before_update) if self.class.before_update end
force_update(&block)
click to toggle source
# File lib/hyalite/component.rb, line 182 def force_update(&block) @updator.enqueue_force_update(self); if block_given? @updator.enqueue_callback(self, &block) end end
init_component(props, context, updator)
click to toggle source
# File lib/hyalite/component.rb, line 19 def init_component(props, context, updator) @props = props @context = context @updator = updator @state = State.new(self, updator, initial_state) @refs = nil end
initial_state()
click to toggle source
# File lib/hyalite/component.rb, line 138 def initial_state self.class.initial_state end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/hyalite/component.rb, line 197 def method_missing(method_name, *args, &block) if @props.has_key?(method_name) @props[method_name] else super end end
pp(obj)
click to toggle source
# File lib/hyalite/component.rb, line 13 def pp(obj) puts obj.inspect end
render()
click to toggle source
# File lib/hyalite/component.rb, line 209 def render end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/hyalite/component.rb, line 205 def respond_to_missing?(method_name, include_private = false) @props.has_key?(method_name) || super end
set_state(states, &block)
click to toggle source
# File lib/hyalite/component.rb, line 189 def set_state(states, &block) @updator.enqueue_set_state(self, states) if block_given? @updator.enqueue_callback(self, &block) end end
Also aliased as: update_state
should_component_update(props, state, context)
click to toggle source
# File lib/hyalite/component.rb, line 178 def should_component_update(props, state, context) true end
state()
click to toggle source
# File lib/hyalite/component.rb, line 142 def state @state.to_h end
state=(state)
click to toggle source
# File lib/hyalite/component.rb, line 146 def state=(state) @state.set(state) end