Class LiveState

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.

Events

Dispatching

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

Listeners

Events which begin with livestate- are assumed to be livestate internal events. The following CustomEvents are supported:

Event Detail type Description
livestate-error LiveStateError Occurs on channel or socket errors
livestate-change LiveStateChange on state:change from channel
livestate-patch LiveStatePatch on state:patch from channel
livestate-connect none on successful socket or channel join

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.

Hierarchy

  • LiveState

Implements

  • EventTarget

Constructors

Properties

channel: Channel
connected: boolean = false
eventTarget: EventTarget
socket: Socket
state: any
stateVersion: number

Methods

  • 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 to socket and join channel. will do nothing if already connected

    Returns void

  • leave channel and disconnect from socket

    Returns void

  • Pushes the event over the channel, adding the lvs_evt: prefix and using the CustomEvent detail property as the payload

    Parameters

    • event: Event

    Returns boolean

  • Parameters

    • type: any
    • error: any

    Returns void

  • Parameters

    • error: any

    Returns void

  • Parameters

    • error: any

    Returns any

  • Parameters

    • __namedParameters: Object

    Returns void

  • Parameters

    • __namedParameters: Object

    Returns void

  • Parameters

    • event: any

    Returns void

  • Parameters

    • eventName: any
    • payload: any

    Returns void

  • Parameters

    • type: any
    • listener: any
    • Optional options: any

    Returns void

  • Deprecated

    Parameters

    • subscriber: Function

    Returns void

  • Deprecated

    Parameters

    • subscriber: any

    Returns void

  • Parameters

    • version: any

    Returns boolean

Generated using TypeDoc