aidenybai / aidenybai/hacky-js

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

オープン
#4 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
48
フォーク
0
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。