1.1.3 • Published 7 years ago
single-batch v1.1.3
single-batch
Low level utility to handle single or batch methods.
Install
$ npm install single-batchUsage
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]wrap(single, batch, context, singleArg)
- single
function() - batch
function() - context
Object= - singleArg
Boolean=false
Returns
nullif single and batch methods are both unavailable{single: function, batch: function}
singleArg
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]])License
MIT