class React::Component::PropsWrapper
Attributes
component[R]
Public Class Methods
define_param(name, param_type)
click to toggle source
# 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] 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 end else props[name] end end end end end
new(component)
click to toggle source
# File lib/react/component/props_wrapper.rb, line 52 def initialize(component) @component = component end
Public Instance Methods
[](prop)
click to toggle source
# File lib/react/component/props_wrapper.rb, line 56 def [](prop) props[prop] end
Private Instance Methods
fetch_from_cache(name) { || ... }
click to toggle source
# File lib/react/component/props_wrapper.rb, line 62 def fetch_from_cache(name) last, value = cache[name] return value if last.equal?(props[name]) yield.tap do |value| cache[name] = [props[name], value] end