aidenybai / aidenybai/hacky-js

feat: clean up intervals, subscriptions, etc. when unmounting

Aperta
#4 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
48
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'd like to do something like this:
```js
function* Component() {
const interval = setInterval(() => {
// Do something
}, 1000);

try {
while (true) {
yield html`Hi`;
}
} finally {
// Runs when unmounting
clearTimeout(interval);
}
}
```

Can it be supported? Or is there already some way to do it?

EDIT: @aidenybai From what I understand, Crank.js does that by calling [`return()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return) on the generator when unmounting, so JS will automatically run the finally blocks. Seems relatively simple. 🤔

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.