Sha256: 203feb1b536783469eb5e9551a2b075c37e65017075c28ad529e45e17ecbff3b

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

module React
  module ReduxComponent
    class AppStoreDefaults
      def initialize(state, component_name)
        @state = state
        if @state.isomorfeus_store
          @state.isomorfeus_store.merge!(application_state: {})
        else
          @state.isomorfeus_store = { application_state: {}}
        end
      end

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

          # check if we have a component local state value
          if @state.isomorfeus_store[:application_state].key?(key)
            return @state.isomorfeus_store[:application_state][key]
          end
        end
        nil
      end

      def to_h
        @state.isomorfeus_store[:application_state]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
isomorfeus-react-16.8.9 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.8 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.7 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.6 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.5 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.4 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.3 lib/react/redux_component/app_store_defaults.rb
isomorfeus-react-16.8.2 lib/react/redux_component/app_store_defaults.rb