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

Add online status #85

Open
NullVoxPopuli opened this issue Feb 21, 2024 · 0 comments
Open

Add online status #85

NullVoxPopuli opened this issue Feb 21, 2024 · 0 comments

Comments

@NullVoxPopuli
Copy link
Contributor

If someone wants to PR this or make it better, that'd be cool

  const OnLine = resource(({ on }) => {
    let online = cell(navigator.onLine);
    let cleanup = new AbortController();
    let signal = cleanup.signal;

    window.addEventListener("offline", (e) => online.current = 'you are offline', { signal });
    window.addEventListener("online", (e) => online.current = 'you are online', { signal });

    on.cleanup(() => signal.abort());

    return () => online.current;
  });

Usage:

{{ OnLine }}

or

class Foo {
  @use online = OnLine;
}
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

1 participant