Sha256: b881da72db4207635982cf8586028a173f62b951bd5f70013a7fe175d298c257

Contents?: true

Size: 1.48 KB

Versions: 29

Compression:

Stored size: 1.48 KB

Contents

module LucidComponent
  class AppStoreProxy
    def initialize(component_instance)
      @native = component_instance.to_n
      @component_instance = component_instance
    end

    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.dispatch(action)
      else
        # check if we have a component local state value
        if `#@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
          a_state = Isomorfeus.store.get_state
          if a_state.key?(:application_state) && a_state[:application_state].key?(key)
            return a_state[:application_state][key]
          end
        end
        if @component_instance.class.default_app_store_defined && @component_instance.class.app_store.to_h.key?(key)
          # check if a default value was given
          return @component_instance.class.app_store.to_h[key]
        end
        # otherwise return nil
        return nil
      end
    end

    def dispatch(action)
      Isomorfeus.store.dispatch(action)
    end

    def subscribe(&block)
      Isomorfeus.store.subscribe(&block)
    end

    def unsubscribe(unsubscriber)
      `unsubscriber()`
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
isomorfeus-react-16.12.24 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.23 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.22 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.21 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.20 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.19 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.18 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.17 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.16 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.15 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.14 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.13 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.12 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.11 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.10 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.9 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.8 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.7 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.6 lib/isomorfeus_react/lucid_component/app_store_proxy.rb
isomorfeus-react-16.12.5 lib/isomorfeus_react/lucid_component/app_store_proxy.rb