class LucidComponent::AppStoreProxy

Public Class Methods

new(component_instance) click to toggle source
# File lib/isomorfeus_react/lucid_component/app_store_proxy.rb, line 3
def initialize(component_instance)
  if component_instance
    @native = component_instance.to_n
    @component_instance = component_instance
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/isomorfeus_react/lucid_component/app_store_proxy.rb, line 10
def [](key)
  method_missing(key)
end
[]=(key, value) click to toggle source
# File lib/isomorfeus_react/lucid_component/app_store_proxy.rb, line 14
def []=(key, value)
  method_missing(key, value)
end
method_missing(key, *args, &block) click to toggle source
# File lib/isomorfeus_react/lucid_component/app_store_proxy.rb, line 18
def method_missing(key, *args, &block)
  if `args.length > 0`
    # set class state, simply a dispatch
    action = { type: 'APPLICATION_STATE', name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
    Isomorfeus.store.collect_and_defer_dispatch(action)
  else
    # check if we have a component local state value
    if @native && `#@native.props.store`
      if `#@native.props.store.application_state && #@native.props.store.application_state.hasOwnProperty(key)`
        return @native.JS[:props].JS[:store].JS[:application_state].JS[key]
      end
    else
      return AppStore[key]
    end
    # otherwise return nil
    return nil
  end
end