aidenybai / aidenybai/hacky-js

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

Open
#4 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
48
Forks
0
PR merge metrics
No merged PRs in 30d

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.