Sha256: 82b3a668994221b2b9e66f857ed514e0c6f70aecd2d05d84d8bbc2ad05fa3700

Contents?: true

Size: 1.6 KB

Versions: 50

Compression:

Stored size: 1.6 KB

Contents

module LucidComponent
  class ClassStoreProxy
    def initialize(component_name, component_instance = nil, native = nil)
      @component_name = component_name
      if component_instance
        @native = native
        @component_instance = component_instance
      end
    end

    def [](key)
      method_missing(key)
    end

    def []=(key, value)
      method_missing(key, value)
    end

    def method_missing(key, *args, &block)
      if `args.length > 0`
        # set class state, simply a dispatch
        action = { type: 'CLASS_STATE', class: @component_name, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
        Isomorfeus.store.collect_and_defer_dispatch(action)
      else
        # get class state
        # check if we have a component local state value
        if @native && @native.JS[:props].JS[:iso_store]
          if @native.JS[:props].JS[:iso_store].JS[:class_state] &&
              @native.JS[:props].JS[:iso_store].JS[:class_state].JS[@component_name] &&
              @native.JS[:props].JS[:iso_store].JS[:class_state].JS[@component_name].JS.hasOwnProperty(key)
            return @native.JS[:props].JS[:iso_store].JS[:class_state].JS[@component_name].JS[key]
          end
        else
          a_state = Isomorfeus.store.get_state
          if a_state.key?(:class_state) && a_state[:class_state].key?(@component_name) && a_state[:class_state][@component_name].key?(key)
            return a_state[:class_state][@component_name][key]
          end
        end
        # otherwise return nil
        return nil
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
isomorfeus-preact-10.6.17 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.16 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.15 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.14 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.13 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.12 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.11 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.10 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.9 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.8 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.7 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.6 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.5 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.4 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.3 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.2 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.1 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.6.0 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.5.11 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb
isomorfeus-preact-10.5.10 lib/isomorfeus_preact/lucid_component/class_store_proxy.rb