Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gustavopch opened this issue Jun 16, 2022 · 1 comment
Open

Comments

@gustavopch
Copy link

gustavopch commented Jun 16, 2022

I'd like to do something like this:

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() on the generator when unmounting, so JS will automatically run the finally blocks. Seems relatively simple. 🤔

@aidenybai
Copy link
Owner

Will look into that return, seems simple (feels kinda like useEffect cleanup function)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants