2.0.1 • Published 7 years ago
bunching v2.0.1
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
cbcb function for processing bunch of datatimeoutNumber interval between cb invokes (optional, default0)optionsObject? options for data handling (optional, default{})options.leadingBoolean if it can be describe as "true", force to invoke cb immediately at start (optional, defaultfalse)options.unfoldBoolean 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.hasherFunction internal functions used to createkeyfrom first argument of bunching call for saving calling arguments in bunch (optional, defaultJSON.stringify)
thisArgany? 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
keyany key to group invoke arguments into bunchargumentsany? arguments which will be bunched and transferred to cb function
Installation
From NPM
via npm
npm install --save bunching
via yarn
yarn add bunching