Sha256: 67a054ea3306a96058014adc469e79a015913f1cb2a12fccb168caa9b92dde72

Contents?: true

Size: 1.78 KB

Versions: 30

Compression:

Stored size: 1.78 KB

Contents

module LucidComponent
  module Reducers
    class << self
      attr_reader :component_reducers_added

      def add_component_reducers_to_store
        unless component_reducers_added
          @_component_reducers_added = true
          component_reducer = Redux.create_reducer do |prev_state, action|
            case action[:type]
            when 'COMPONENT_STATE'
              if action.key?(:set_state)
                action[:set_state]
              else
                new_state = {}.merge!(prev_state) # make a copy of state
                new_state[action[:object_id]] = {} unless new_state.key?(action[:object_id])
                new_state[action[:object_id]].merge!(action[:name] => action[:value])
                # new_state == prev_state ? prev_state : new_state
                new_state
              end
            else
              prev_state
            end
          end

          component_class_reducer = Redux.create_reducer do |prev_state, action|
            case action[:type]
            when 'COMPONENT_CLASS_STATE'
              if action.key?(:set_state)
                action[:set_state]
              else
                new_state = {}.merge!(prev_state) # make a copy of state
                new_state[action[:class]] = {} unless new_state.key?(action[:class])
                new_state[action[:class]].merge!(action[:name] => action[:value])
                # new_state == prev_state ? prev_state : new_state
                new_state
              end
            else
              prev_state
            end
          end
          Redux::Store.preloaded_state_merge!(component_state: {}, component_class_state: {})
          Redux::Store.add_reducers(component_state: component_reducer, component_class_state: component_class_reducer)
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
isomorfeus-react-16.12.4 lib/lucid_component/reducers.rb
isomorfeus-react-16.12.3 lib/lucid_component/reducers.rb
isomorfeus-react-16.12.2 lib/lucid_component/reducers.rb
isomorfeus-react-16.12.1 lib/lucid_component/reducers.rb
isomorfeus-react-16.12.0 lib/lucid_component/reducers.rb
isomorfeus-react-16.11.4 lib/lucid_component/reducers.rb
isomorfeus-react-16.11.3 lib/lucid_component/reducers.rb
isomorfeus-react-16.11.2 lib/lucid_component/reducers.rb
isomorfeus-react-16.11.1 lib/lucid_component/reducers.rb
isomorfeus-react-16.11.0 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.17 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.16 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.14 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.13 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.12 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.11 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.10 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.9 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.8 lib/lucid_component/reducers.rb
isomorfeus-react-16.10.7 lib/lucid_component/reducers.rb