-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (26 loc) · 794 Bytes
/
index.js
File metadata and controls
30 lines (26 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
createReducer.compose = compose
module.exports = createReducer
function createReducer (handlers, getInitialState) {
var gisType = typeof getInitialState
if (!(gisType === 'function' || gisType === 'undefined')) {
throw new Error('If needed, second argument should be function to be called when state is undefined.')
}
return function (state, action) {
var handler = handlers[action.type]
if (typeof state === 'undefined' && gisType === 'function') {
state = getInitialState(action)
}
return (
typeof handler === 'function' ?
handler.call(handlers, state, action) :
state
)
}
}
function compose (fns) {
return function (state, action) {
return fns.reduce(function (last, fn) {
return fn(last, action)
}, state)
}
}