README
Deprecated in favor to Wraperizer.bunching. No longer support.
Create function to bunching data of multiply bunching function invokes and processing them after timeout
with cb function
Parameters
cb
cb function for processing bunch of datatimeout
Number interval between cb invokes (optional, default0
)options
Object? options for data handling (optional, default{}
)options.leading
Boolean if it can be describe as "true", force to invoke cb immediately at start (optional, defaultfalse
)options.unfold
Boolean if it can be describe as "true", every bunched data element will be transfered to cb as separate element, otherwise data will be transfered as an array (optional, defaultfalse
)options.hasher
Function internal functions used to createkey
from first argument of bunching call for saving calling arguments in bunch (optional, defaultJSON.stringify
)
thisArg
any? context for cb call
Examples
import bunching from 'bunching';
// const bunching = require('bunching').default;
function handler() {
console.dir(arguments, {colors: true, depth: null});
// returns Array with up to 36 elements, not 1000 (3000/3)
}
const INTERVAL_BUNCHED = 3000;
const INTERVAL_INVOKE = 3;
const invoke = bunching(handler, INTERVAL_BUNCHED, {leading: true, unfold: true});
setInterval(function () {
let key = Math.round(Math.random() * 35);
let value1 = Math.round(Math.random() * 35).toString(36);
let value2 = Math.round(Math.random() * 999);
invoke(key, value1, value2)
}, INTERVAL_INVOKE);
Returns bunching
cb
Type: Function
Parameters
bunch
data bunch - dictionary grouped by first argument of bunching invoke (as a key)
bunching
function which will be called and aggregate data into a bunch
Parameters
key
any key to group invoke arguments into buncharguments
any? arguments which will be bunched and transferred to cb function
Installation
From NPM
via npm
npm install --save bunching
via yarn
yarn add bunching