Skip to content

Instantly share code, notes, and snippets.

View scottbarrow's full-sized avatar

Scott Barrow scottbarrow

View GitHub Profile
@scottbarrow
scottbarrow / README.md
Created October 28, 2020 15:21 — forked from leastbad/README.md
stimulus-websocket preview

This controller can be put on body or any other element.

  1. Adds a websocket accessor to the element
  2. Controller exposes a connected boolean getter
  3. Controller bails with a warning if no shared consumer is available
  4. Element will have data-action-cable-connected or data-action-cable-disconnected attributes which can be used for CSS selectors
  5. Element will emit action-cable:connected or action-cable:disconnected events only when state is flipping
  6. Errors => Disconnected to keep things simple

I intend to document the navigator.onLine accessor and the window:online/offline events so devs can handle PWA modes.

### Keybase proof
I hereby claim:
* I am scottbarrow on github.
* I am scottbarrow (https://keybase.io/scottbarrow) on keybase.
* I have a public key ASD_SKprBc0b4SWsmhDBFVPYoffyloIVFZTq9RP4RP5qGAo
To claim this, I am signing this object: