node package manager

bunching

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 data
  • timeout Number interval between cb invokes (optional, default 0)
  • 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, default false)
    • 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, default false)
    • options.hasher Function internal functions used to create key from first argument of bunching call for saving calling arguments in bunch (optional, default JSON.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 bunch
  • arguments 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