# binary-throttle

> 双函数约束节流 😏

Latest version **2.3.0** (published 2019-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install binary-throttle
pnpm add binary-throttle
yarn add binary-throttle
bun add binary-throttle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2019-06-10 |
| First published | 2019-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 652.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | soulizs |
| Maintainers | soulizs |

## Links

- npm: https://www.npmjs.com/package/binary-throttle
- Repository: https://github.com/soulizs/BT
- Homepage: https://github.com/soulizs/BT#readme
- Issues: https://github.com/soulizs/BT/issues
- npm.io page: https://npm.io/package/binary-throttle

## Recent versions

- 2.3.0 (latest) — 2019-06-10
- 2.2.0 — 2019-06-07
- 2.1.0 — 2019-06-07
- 2.0.0 — 2019-06-07
- 1.0.0 — 2019-06-07

## README

# BT(binary-throttle)
双函数约束节流 😏

## 安装
```
yarn add binary-throttle
```

## 使用
```js
import { BT } from "binary-throttle";

function forward() {
  // @TODO
}

function backward() {
  // @TODO
}

const [X, Y] = BT(forward, backward, {
  // idleness: 1000,
  // fallbackF: () => console.log('X was ignore this time.'),
  // fallbackB: () => console.log('Y was ignore this time.')
});
```

## 背景
假设存在A/B函数相互关联，A函数每次一次正向操作，B函数必然会执行一次反向操作，A/B函数保证相关抵消。
那么考虑以下场景:

ABABABABABABABABABABABABABABABABABAB

A/B函数高频率触发，但是最终效果都是抵消的，此时如果基于用户交互优化，以及节约性能的考虑，可以进行约束节流。
不改变最终的效果，但是可以减少触发次数。优化可能如下：

A----------B----------A------------B

## 技术方案
通过计数器以及定时器，以及高阶函数，以及标识参数，将原有A/B函数包裹，实现根据参数值（限制原始类型）进行约束节流的功能。

效果如下（运行`npm test`）

<img alt="database" src="./database.png" />

---
_Source: https://npm.io/package/binary-throttle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
