Archived
1
0
Fork 0

Add basic reducer class Obredux::Reducer

This commit is contained in:
Braiden Vasco 2017-07-28 02:34:58 +00:00
parent f1786e5877
commit d60ed0f02b
2 changed files with 23 additions and 10 deletions

View file

@ -20,4 +20,24 @@ module Obredux
@state = reducer_klass.new(state, action).call
end
end
class Reducer
def initialize(state, action)
@state = state
@action = action
end
def call
@state = initial_state if state.equal? UNDEFINED
reduce
end
private
attr_reader :state, :action
def initial_state
raise NotImplementedError, "#{self.class}#initial_state"
end
end
end

View file

@ -1,12 +1,7 @@
# frozen_string_literal: true
class Reducer
attr_reader :state, :action
def initialize(state, action)
@state = state
@action = action
end
class Reducer < Obredux::Reducer
private
def initial_state
{
@ -83,9 +78,7 @@ class Reducer
}.freeze
end
def call
@state = initial_state if state == Obredux::UNDEFINED
def reduce
case action
when Actions::LoadFriends
load_friends