Skip to content

Add online status #85

@NullVoxPopuli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions