Skip to content

Add online status #85

Description

@NullVoxPopuli

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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions