-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.js
27 lines (25 loc) · 830 Bytes
/
helpers.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
var curry = require('ramda/src/curry')
var concat = require('ramda/src/concat')
var compose = require('ramda/src/compose')
var map = require('ramda/src/map')
var mergeAll = require('ramda/src/mergeAll')
var methodized = curry(function(actionDefs, prefix, name) {
var obj = {}
var type = prefix === false ? name : concat(prefix + '_', name)
var meta = actionDefs[name].meta ? actionDefs[name].meta : null
obj[name] = function(payload) {
return {
type: type,
payload: payload,
error: payload instanceof Error,
meta: meta
}
}
return obj
})
exports.methodized = methodized
var methodObject = curry(function(prefix, actionDefs) {
var names = Object.keys(actionDefs)
return compose(mergeAll, map(methodized(actionDefs, prefix)))(names)
})
exports.methodObject = methodObject