Module: Fron::Behaviors::Components

Included in:
Component
Defined in:
opal/fron/core/behaviors/components.rb

Overview

Components

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.component(registry) ⇒ Object

Creates components from the registry


16
17
18
19
20
21
22
# File 'opal/fron/core/behaviors/components.rb', line 16

def self.component(registry)
  registry.each do |args|
    arguments = args.dup
    block = arguments.last.is_a?(Proc) ? arguments.pop : nil
    component(*arguments, &block)
  end
end

.included(base) ⇒ Object

Runs for included classes


9
10
11
# File 'opal/fron/core/behaviors/components.rb', line 9

def self.included(base)
  base.register self, [:component]
end

Instance Method Details

#component(name, comp, &block) ⇒ Object

Creates a child component


29
30
31
32
33
34
35
36
37
38
39
# File 'opal/fron/core/behaviors/components.rb', line 29

def component(name, comp, &block)
  component = comp.is_a?(Class) ? comp.new(nil) : Component.new(comp)
  component.instance_eval(&block) if block
  self << component
  instance_variable_set "@#{name}", component

  return if respond_to?(name)
  define_singleton_method name do
    instance_variable_get("@#{name}")
  end
end