The throttle is not performing as expected.
- 主要语言
- TypeScript
- 星标
- 229
- 派生
- 18
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 2
描述
The throttle of this library does not perform throttling (it behaves differently from what is described in the tests and documentation).
You will understand if you try the following reproduction code in [RunKit](https://npm.runkit.com/%40github%2Fmini-throttle). Instead of behaving like [the marble in the test cases](https://github.com/github/mini-throttle/blob/7fb6f52c98c735fe44f6096c8bddd051976d3ae0/test/index.ts#L167), it appears to perform a complete debounce operation, firing only once at the start and once at the end.
> | throttle(fn, 100) | 1 2 4 6 8 10 |

```javascript
var {throttle} = require("@github/mini-throttle")
const delay = (m) => new Promise(r => setTimeout(r, m))
const fn = throttle((...x)=>{console.log(x)},1000)
for (let i = 1; i <= 10; ++i) {
fn(i)
await delay(100)
}
await delay(1000)
```
---
You can also repro this in the following CodeSandbox. Please rapidly click the button. While the expected throttle behavior is that of lodash.throttle, but mini-throttle does not perform as its name "throttle".
https://codesandbox.io/p/sandbox/damp-browser-fyd2g4?file=/src/index.js:24,11
贡献指南
调研方向
先从 test/index.ts 中第 167 行附近的 marble 所描述的 throttle 行为开始,然后运行链接的 RunKit 或 CodeSandbox 复现,以比较实际调用和预期调用。跟踪 throttle 的入口点,并验证重复调用产生的是文档所述的类似 lodash.throttle 的时序,而不是 debounce 行为;当复现和相关测试与 marble 匹配时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100