https://github.com/richienb/batched-function
Batch multiple function calls into a single one
https://github.com/richienb/batched-function
Last synced: 6 months ago
JSON representation
Batch multiple function calls into a single one
- Host: GitHub
- URL: https://github.com/richienb/batched-function
- Owner: Richienb
- License: mit
- Created: 2023-02-04T02:15:45.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-09T08:18:14.000Z (over 2 years ago)
- Last Synced: 2025-06-24T14:45:10.203Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 20.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# batched-function
> Batch multiple function calls into a single one
Useful for collecting DOM updates.
## Install
```sh
npm install batched-function
```
## Usage
```js
import batchedFunction from 'batched-function';
const batched = batchedFunction(values => {
console.log(values);
});
batched('🦄');
batched('🌈');
batched('🐻');
// Logs ['🦄', '🌈', '🐻']
```
## API
### batchedFunction(function_, options?)
After a value is passed, `function_` is called `interval` milliseconds later with an array of all the values passed in that time, including the first one.
#### options
Type: `object`
##### delay
Type: `number`\
Default: `undefined`
How long to wait in milliseconds before calling the function. If `undefined`, which is by default, the function is called in the next [microtask](https://javascript.info/microtask-queue).