Sha256: 6878492e47ace2674fc460cd17dbff11b6598b537c50ecbfcf0dbb7d1f807ee2

Contents?: true

Size: 1.78 KB

Versions: 20

Compression:

Stored size: 1.78 KB

Contents

module LucidApp
  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

20 entries across 20 versions & 1 rubygems

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