This is the lower level API for LiveState. It connects to a
live_state channel over websockets and is responsible
for maintaining the state. From the channel it receives state:change events which
replace the state entirely, or state:patch events which contain a json
patch to be applied.
A CustomEvent dispatched to LiveState will be pushed over the channel as
event with the lvs_evt: prefix and the detail property will become the payload
Will occur on channel or socket errors. The detail will consist of
Any other event name not prefixed with livestate- will be assumed to be a channel
event and will result in a event being listened to on the channel, which when
received, will be dispatched as a CustomEvent of the same name with the payload
from the channel event becoming the detail property.
for events that begin with 'livestate-', add a listener. For
other events, additionally call channel.on to receive the event
over the channel, which will then be dispatched.
Parameters
type: any
listener: any
Optional options: any
Returns void
connect
connect(): void
connect to socket and join channel. will do nothing if already connected
Returns void
disconnect
disconnect(): void
leave channel and disconnect from socket
Returns void
dispatchEvent
dispatchEvent(event: Event): boolean
Pushes the event over the channel, adding the lvs_evt: prefix and using the CustomEvent
detail property as the payload
This is the lower level API for LiveState. It connects to a live_state channel over websockets and is responsible for maintaining the state. From the channel it receives
state:change
events which replace the state entirely, orstate:patch
events which contain a json patch to be applied.Events
Dispatching
A
CustomEvent
dispatched to LiveState will be pushed over the channel as event with thelvs_evt:
prefix and the detail property will become the payloadListeners
Events which begin with
livestate-
are assumed to be livestate internal events. The following CustomEvents are supported:state:change
from channelstate:patch
from channelWill occur on channel or socket errors. The
detail
will consist ofAny other event name not prefixed with
livestate-
will be assumed to be a channel event and will result in a event being listened to on the channel, which when received, will be dispatched as a CustomEvent of the same name with the payload from the channel event becoming thedetail
property.