Leaf
    Preparing search index...

    Class EphemeralStore<T>

    EphemeralStore is a structure that allows to track the ephemeral state of the peers.

    It can be used to synchronize cursor positions, selections, and the names of the peers. Each entry uses timestamp-based LWW (Last-Write-Wins) for conflict resolution.

    If we don't receive a state update from a peer within the timeout, we will remove their state. The timeout is in milliseconds. This can be used to handle the offline state of a peer.

    const store = new EphemeralStore();
    const store2 = new EphemeralStore();
    // Subscribe to local updates
    store.subscribeLocalUpdates((data)=>{
    store2.apply(data);
    })
    // Subscribe to all updates
    store2.subscribe((event)=>{
    console.log("event: ", event);
    })
    // Set a value
    store.set("key", "value");
    // Encode the value
    const encoded = store.encode("key");
    // Apply the encoded value
    store2.apply(encoded);

    Type Parameters

    Index

    Constructors

    • Type Parameters

      Parameters

      • Optionaltimeout: number

      Returns EphemeralStore<T>

    Properties

    Methods

    • Parameters

      • bytes: Uint8Array

      Returns void

    • Returns void

    • Parameters

      • key: string

      Returns Uint8Array

    • Returns Uint8Array

    • Parameters

      • key: string

      Returns undefined | T

    • Returns Record<string, T>

    • Returns string[]

    • Parameters

      • key: string
      • value: T

      Returns void

    • Parameters

      Returns () => void