Class TlDrawSyncedStorage<T>

The TlDrawSyncedStorage class manages synchronized storage for drawing states using Y.js and y-websocket.

Type Parameters

  • T extends SyncedStorageState

    Type parameter extending from SyncedStorageState, represents the state structure.

Constructors

  • Constructs an instance of TlDrawSyncedStorage.

    Type Parameters

    • T extends SyncedStorageState

    Parameters

    • roomId: string

      The identifier for the room, used for data segregation.

    • initialState: T

      The initial state to populate the storage with.

    • serverUrl: string

      The URL of the WebSocket server.

    Returns TlDrawSyncedStorage<T>

Properties

doc: Doc
provider: WebsocketProvider
state: YKeyValue<T>

Accessors

  • get room(): WebsocketProvider
  • Gets the WebSocket provider associated with this storage.

    Returns WebsocketProvider

    The WebsocketProvider instance.

Methods

  • Deletes parts of the state based on the provided newState object.

    Parameters

    • newState: Partial<T>

      The state changes to apply, specifying the keys to delete.

    Returns void

  • Disconnects and disposes of the resources used by this TlDrawSyncedStorage instance.

    Returns void

  • Retrieves the current state as an array.

    Returns any[]

    An array representing the current state.

  • Initializes the storage with the provided initial state.

    Parameters

    • initialState: T

      The initial state to set.

    Returns void

  • Registers a callback to be called when the state changes.

    Parameters

    • callback: ((diff, transaction) => void)

      The function to be called with the changes and transaction when the state changes.

        • (diff, transaction): void
        • Parameters

          Returns void

    Returns void

  • Unregisters a callback from being called when the state changes.

    Parameters

    • callback: ((diff, transaction) => void)

      The callback function to unregister.

        • (diff, transaction): void
        • Parameters

          Returns void

    Returns void

  • Sets the state based on the provided newState object.

    Parameters

    • newState: Partial<T>

      The new state to apply.

    Returns void

Generated using TypeDoc