![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
batcher-js
Advanced tools
Batching with ease, like debounce but you don't miss intermediate calls
Batch function calls with ease :)
It's like a debounce but you don't need to miss the intermediate calls.
Batcher aggregates your options and group calls in a given interval using a function hash, so you can avoid repetitive calls to the same function.
$ npm install --save batcher-js
const batch = batcher(myMethod);
const callback1 = () => 'callback1';
const callback2 = () => 'callback2';
batch({id: 1}, callback1);
batch({id: 2}, callback1);
batch({id: 3}, callback1);
batch({id: 4}, callback1);
batch({id: 5}, callback1);
batch({id: 6}, callback2);
batch({id: 7}, callback2);
// there will be only two calls to myMethod:
// -> myMethod([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}], callback1); //and
// -> myMethod([{id: 6}, {id: 7}], callback2);
More examples available in test.js
Definitions are included.
import Batcher from "batcher-js";
More examples available in batcher-js-tests.ts
Returns a batch method to wrap each call to be batched. Use one for each purpose.
Type: function
The method to be batched
Type: object
Default: {
interval: 0,
maximum: null
}
Custom settings for the batcher. It allows to customize:
- interval
: the interval between calls to be batched - defaults to 0 meaning that only calls in the same cycle of the event loop are going to be batched; Increase the number for more tolerance.
- maximum
: the maximum ammount of calls to be batched - defaults to null or no limit. Use this number if your api has a limit.
The return of a call for batcher()
Type: any
The arguments to be passed to the batched method. It will be pushed to an Array and passed to the method at the end of the batch.
Type: function
The callback to be passed to the batched method. Calls are grouped based on the hash of this method.
MIT © Leandro Lemos
FAQs
Batching with ease, like debounce but you don't miss intermediate calls
We found that batcher-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.