Class: React::Component::PropsWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/react/component/props_wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ PropsWrapper

Returns a new instance of PropsWrapper.



52
53
54
# File 'lib/react/component/props_wrapper.rb', line 52

def initialize(component)
  @component = component
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



10
11
12
# File 'lib/react/component/props_wrapper.rb', line 10

def component
  @component
end

Class Method Details

.define_param(name, param_type) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/react/component/props_wrapper.rb', line 12

def self.define_param(name, param_type)
  if param_type == Observable
    define_method("#{name}") do
      value_for(name)
    end
    define_method("#{name}!") do |*args|
      current_value = value_for(name)
      if args.count > 0
        props[name].call args[0]
        current_value
      else
        # rescue in case we in middle of render... What happens during a
        # render that causes exception?
        # Where does `dont_update_state` come from?
        props[name].call current_value unless @dont_update_state rescue nil
        props[name]
      end
    end
  elsif param_type == Proc
    define_method("#{name}") do |*args, &block|
      props[name].call(*args, &block) if props[name]
    end
  else
    define_method("#{name}") do
      fetch_from_cache(name) do
        if param_type.respond_to? :_react_param_conversion
          param_type._react_param_conversion props[name], nil
        elsif param_type.is_a?(Array) &&
          param_type[0].respond_to?(:_react_param_conversion)
          props[name].collect do |param|
            param_type[0]._react_param_conversion param, nil
          end
        else
          props[name]
        end
      end
    end
  end
end

Instance Method Details

#[](prop) ⇒ Object



56
57
58
# File 'lib/react/component/props_wrapper.rb', line 56

def [](prop)
  props[prop]
end