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.



54
55
56
# File 'lib/react/component/props_wrapper.rb', line 54

def initialize(component)
  @component = component
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



5
6
7
# File 'lib/react/component/props_wrapper.rb', line 5

def component
  @component
end

Class Method Details

.define_all_others(name) ⇒ Object



47
48
49
50
51
# File 'lib/react/component/props_wrapper.rb', line 47

def self.define_all_others(name)
  define_method("#{name}") do
    @_all_others_cache ||= yield(props)
  end
end

.define_param(name, param_type) ⇒ Object



7
8
9
10
11
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
# File 'lib/react/component/props_wrapper.rb', line 7

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



58
59
60
# File 'lib/react/component/props_wrapper.rb', line 58

def [](prop)
  props[prop]
end

#_reset_all_others_cacheObject



63
64
65
# File 'lib/react/component/props_wrapper.rb', line 63

def _reset_all_others_cache
  @_all_others_cache = nil
end