github / github/mini-throttle

The throttle is not performing as expected.

Aperta
#23 0 commenti 4 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
229
Fork
18
Merge medio
1g 10h
PR unite (30g)
2

Descrizione

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 |

![image](https://github.com/github/mini-throttle/assets/7282145/454d4d46-014a-45ca-88ec-0ddcb03a7342)

```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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with the throttle behavior described by the marble in test/index.ts around line 167, then run the linked RunKit or CodeSandbox reproduction to compare actual and expected calls. Trace the throttle entry point and verify that repeated calls produce the documented lodash.throttle-like timing rather than debounce behavior; done means the reproduction and relevant tests match the marble.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.