add gs
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
--[[
|
||||
Create a composite reducer from a map of keys and sub-reducers.
|
||||
]]
|
||||
local function combineReducers(map)
|
||||
return function(state, action)
|
||||
-- If state is nil, substitute it with a blank table.
|
||||
if state == nil then
|
||||
state = {}
|
||||
end
|
||||
|
||||
local newState = {}
|
||||
|
||||
for key, reducer in pairs(map) do
|
||||
-- Each reducer gets its own state, not the entire state table
|
||||
newState[key] = reducer(state[key], action)
|
||||
end
|
||||
|
||||
return newState
|
||||
end
|
||||
end
|
||||
|
||||
return combineReducers
|
||||
Reference in New Issue
Block a user