Low level utility to handle single or batch methods.
$ npm install single-batch
import wrap from 'single-batch'
const obj = {
add: (a, b) => Promise.resolve(a + b)
}
const wrapped = wrap('add', null, obj)
wrapped.single(1, 2).then(console.log) // 3
wrapped.batch([1, 2], [2, 3]).then(console.log) // [3, 4]
- single
function()
- batch
function()
- context
Object=
- singleArg
Boolean=false
Returns
null
if single and batch methods are both unavailable{single: function, batch: function}
If true, then wrapped.single
only accept one argument, and each argument of wrapped.batch
corresponds to the argument of wrapped.single
// singleArg: true
wrapped.single(1)
wrapped.batch(1, 2, 3)
wrapped.single([1, 2])
wrapped.batch([1, 2], [2, 3])
If false, wrapped.single
accept multiple arguments, and each argument of wrapped.batch
must be an array which represents the arguments of wrapped.single
wrapped.single(1, 2)
wrapped.batch([1, 2], [2, 3])
wrapped.single([1, 2])
wrapped.batch([[1, 2]], [[2, 3]])
MIT