Class: React::Component::PropsWrapper
- Defined in:
- lib/react/component/props_wrapper.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
Class Method Summary collapse
Instance Method Summary collapse
- #[](prop) ⇒ Object
- #_reset_all_others_cache ⇒ Object
-
#initialize(component) ⇒ PropsWrapper
constructor
A new instance of PropsWrapper.
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
#component ⇒ Object (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 |