batchcalls

0.4.1 • Public • Published

batchcalls

Batches calls to a function and passes arguments as arrays

var batchCalls = require('batchcalls');
var request = batchCalls(function (ids) {
  fetch('/users/?ids=' + ids.join(',')).then(doSomething);
});
var ids = ['1', '2', '3'];
 
ids.forEach(request);
var batchCalls = require('batchcalls');
var clicksWithinSecond = batchCalls(function (events) {
  // Do something
}, {
  wait: 1000
});
 
document.body.addEventListener('click', clicksWithinSecond);
var batchCalls = require('batchcalls');
var executeAfter5Clicks = batchCalls(function (events) {
  // Do something
}, {
  count: 5
});
 
document.body.addEventListener('click', executeAfter5Clicks);
var batchCalls = require('batchcalls');
var executeOnConditional = batchCalls(function (batchedArgs) {
  // Will batch as long as conditional is true
}, {
  conditional: function (args, prevArgs) {
    return args[0].foo === prevArgs[0].foo;
  }
});

Readme

Keywords

Package Sidebar

Install

npm i batchcalls

Weekly Downloads

1

Version

0.4.1

License

MIT

Last publish

Collaborators

  • christianalfoni