-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
42 lines (38 loc) · 1.4 KB
/
index.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
import defaultLog from "./defaultLog"
export default function(options) {
options = options || {}
options.log = typeof options.log === "function" ? options.log : defaultLog
return function(app) {
return function(initialState, actionsTemplate, view, container) {
function enhanceActions(actions, prefix) {
var namespace = prefix ? prefix + "." : ""
return Object.keys(actions || {}).reduce(function(otherActions, name) {
var namedspacedName = namespace + name
var action = actions[name]
otherActions[name] =
typeof action === "function"
? function(data) {
return function(state, actions) {
var result = action(data)
result =
typeof result === "function"
? result(state, actions)
: result
options.log(
state,
{ name: namedspacedName, data: data },
result
)
return result
}
}
: enhanceActions(action, namedspacedName)
return otherActions
}, {})
}
var enhancedActions = enhanceActions(actionsTemplate)
var appActions = app(initialState, enhancedActions, view, container)
return appActions
}
}
}