Module: React::FunctionComponent::Creator

Defined in:
lib/react/function_component/creator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/react/function_component/creator.rb', line 4

def self.extended(base)
  %x{
    base.react_component = function(props) {
      Opal.React.render_buffer.push([]);
      Opal.React.active_components.push(base);
      #{base.new(`props`).instance_exec(&`base.function_block`)};
      Opal.React.active_components.pop();
      return Opal.React.render_buffer.pop();
    }
  }

  base_module = base.to_s.deconstantize
  if base_module != ''
    base_module.constantize.define_singleton_method(base.to_s.demodulize) do |*args, &block|
      `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
    end
  else
    Object.define_method(base.to_s) do |*args, &block|
      `Opal.React.internal_prepare_args_and_render(#{base}.react_component, args, block)`
    end
  end

  def create_function(&block)
    `base.function_block = #{block}`
  end
end

Instance Method Details

#create_function(&block) ⇒ Object



26
27
28
# File 'lib/react/function_component/creator.rb', line 26

def create_function(&block)
  `base.function_block = #{block}`
end