class Rudux::MutatingReducer
Public Class Methods
base()
click to toggle source
# File lib/rudux/mutating_reducer.rb, line 45 def self.base Rudux::Combined.new({}) end
reduce(states, action)
click to toggle source
# File lib/rudux/mutating_reducer.rb, line 6 def self.reduce states, action if states.is_a? Array reduce_array_of_states(states, action) elsif states.is_a? Hash reduce_hash_of_states(states, action) else reduce_single_state(states, action) end end
reduce_array_of_states(states, action)
click to toggle source
# File lib/rudux/mutating_reducer.rb, line 16 def self.reduce_array_of_states states, action states.map do |state| reduce_single_state(state, action) end end
reduce_hash_of_states(hash, action)
click to toggle source
# File lib/rudux/mutating_reducer.rb, line 22 def self.reduce_hash_of_states hash, action hash.map do |state| result = reduce_single_state(state[1], action) Hash[result.id, result] end.reduce(&:merge!) end
reduce_single_state(state, action)
click to toggle source
# File lib/rudux/mutating_reducer.rb, line 29 def self.reduce_single_state state, action base = self.base.reduce(state, action) if self.respond_to? action.to_sym this = self.send(action.to_sym, state, action) else this = {} end merged = base.merge!(this) if merged.empty? state else # TODO: Everything but this line is essentially a copy of Rudux::Reducer state.mutate(merged) end end