Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itsdouges/function-batch
📦 Higher order function that will batch all calls to the wrapped function over a time period, and then call the wrapped function once with all args.
https://github.com/itsdouges/function-batch
batch batch-function es2015 es6 function function-batch function-to-promise javascript
Last synced: 29 days ago
JSON representation
📦 Higher order function that will batch all calls to the wrapped function over a time period, and then call the wrapped function once with all args.
- Host: GitHub
- URL: https://github.com/itsdouges/function-batch
- Owner: itsdouges
- License: mit
- Created: 2017-04-10T12:19:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-05T23:59:18.000Z (over 7 years ago)
- Last Synced: 2024-04-25T05:20:47.887Z (7 months ago)
- Topics: batch, batch-function, es2015, es6, function, function-batch, function-to-promise, javascript
- Language: JavaScript
- Homepage:
- Size: 114 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# [function-batch](https://github.com/madou/function-batch)
[![NPM version](http://img.shields.io/npm/v/function-batch.svg?style=flat-square)](https://www.npmjs.com/package/function-batch)
[![NPM downloads](http://img.shields.io/npm/dm/function-batch.svg?style=flat-square)](https://www.npmjs.com/package/function-batch)
[![Build Status](http://img.shields.io/travis/madou/function-batch/master.svg?style=flat-square)](https://travis-ci.org/madou/function-batch)
[![codecov](https://codecov.io/gh/madou/function-batch/branch/master/graph/badge.svg)](https://codecov.io/gh/madou/function-batch)
[![Dependency Status](http://img.shields.io/david/madou/function-batch.svg?style=flat-square)](https://david-dm.org/madou/function-batch)> Higher order function that will batch all calls to the wrapped function over a debounce, and then call the wrapped function once.
## How to Install
```sh
npm install function-batch
```## Usage
```javascript
import functionBatch from 'function-batch';const returnArr = (arr) => arr;
const returnArrBatched = functionBatch(returnArr);const value = Promise.all([
returnArrBatched([1]);
returnArrBatched([2]);
returnArrBatched([3]);
returnArrBatched([4]);
])
.then(([a, b, c, d]) => {
// All resolve with the same value.
// a = [1, 2, 3, 4]
// b = [1, 2, 3, 4]
// c = [1, 2, 3, 4]
// d = [1, 2, 3, 4]
});
```Currently `function-batch` only supports batching up arrays.
Support for different kinds of args will be added if requested!## Api
### function: functionBatch(func, wait, options): Promise<*>
| param | type | required |
|---------|----------|----------|
| func | Function | yes |
| wait | number | yes |
| options | Options | no |### object: Options
| param | type | required |
|----------|---------|----------|
| leading | boolean | no |
| trailing | boolean | no |
| maxWait | number | no |