aidenybai / aidenybai/hacky-js

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

Abierto
#4 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
48
Forks
0
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.