aidenybai / aidenybai/hacky-js

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

Ouverte
#4 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
48
Forks
0
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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. 🤔

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.