Sha256: 400934d3258cfa21bf86b6bcc9d21033c1823289544369b8acf7614248b63342

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

module React
  module ReduxComponent
    class ComponentInstanceStoreDefaults
      def initialize(state, component_name)
        @state = {}
        @component_name = component_name
      end

      def method_missing(key, *args, &block)
        if `args.length > 0`
          # set initial class state
          key = key.chop if `key.endsWith('=')`
          @state[key] = args[0]
          current_state = Isomorfeus.store.get_state
          if !(current_state[:component_class_state].has_key?(@component_name) &&
            current_state[:component_class_state][@component_name].has_key?(:instance_defaults) &&
            current_state[:component_class_state][@component_name][:instance_defaults].has_key?(key))
            Isomorfeus.store.dispatch(type: 'COMPONENT_CLASS_STATE', class: @component_name, name: :instance_defaults, value: { key => args[0]})
          end
        else
          # get class state

          # check if we have a component local state value

          if @state.has_key?(key)
            return @state[key]
          end
        end
        nil
      end

      def to_h
        @state
      end

      def to_n
        @state.to_n
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
isomorfeus-react-16.8.1 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.8.0 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.8 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.7 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.6 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.5 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.4 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.3 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.2 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.6.1 lib/react/redux_component/component_instance_store_defaults.rb
isomorfeus-react-16.5.1 lib/react/redux_component/component_instance_store_defaults.rb