1.1.3 • Published 6 years ago

single-batch v1.1.3

Weekly downloads
70
License
MIT
Repository
github
Last release
6 years ago

Build Status Coverage

single-batch

Low level utility to handle single or batch methods.

Install

$ npm install single-batch

Usage

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

  • null if 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

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.0

7 years ago