@yorkie-js/sdk
    Preparing search index...

    Class Document<R, P>

    Document is a CRDT-based data type. We can represent the model of the application and edit it even while offline. It implements Attachable interface to be managed by Attachment.

    Type Parameters

    Implements

    • Attachable
    Index

    Constructors

    Properties

    history: {
        canRedo: () => boolean;
        canUndo: () => boolean;
        redo: () => void;
        undo: () => void;
    }

    history is exposed to the user to manage undo/redo operations.

    Methods

    • addOnlineClient adds the given clientID into the online client set.

      Parameters

      • clientID: string

      Returns void

    • applyChangePack applies the given change pack into this document.

      1. Remove local changes applied to server.
      2. Update the checkpoint.
      3. Do Garbage collection.

      Parameters

      • pack: ChangePack<P>

      Returns void

    • applyDocEvent applies the given doc event into this document.

      Parameters

      • type: DocEventType
      • publisher: string

      Returns void

    • applySnapshot applies the given snapshot into this document.

      Parameters

      • serverSeq: bigint
      • snapshotVector: VersionVector
      • Optionalsnapshot: Uint8Array<ArrayBufferLike>
      • clientSeq: number = -1

      Returns void

    • applyWatchInit applies the watch initialization with the given client IDs.

      Parameters

      • clientIDs: string[]

      Returns void

    • clearHistory flushes both undo and redo stacks. This is used after applying a snapshot or initialRoot so that setup operations are not reachable via undo.

      Returns void

    • createChangePack create change pack of the local changes to send to the remote server.

      Returns ChangePack<P>

    • getChangeID returns the change id of this document.

      Returns ChangeID

    • getCheckpoint returns the checkpoint of this document.

      Returns Checkpoint

    • getClone returns this clone.

      Returns { presences: Map<string, P>; root: CRDTRoot } | undefined

    • getCloneRoot returns clone object.

      Returns CRDTObject | undefined

    • getGarbageLen returns the length of elements should be purged.

      Returns number

    • getGarbageLenFromClone returns the length of elements should be purged from clone.

      Returns number

    • getKey returns the key of this document.

      Returns string

    • getMaxSizePerDocument gets the maximum size of this document.

      Returns number

    • getOthersForTest returns all the other clients in online, sorted by clientID.

      Returns { clientID: string; presence: P }[]

    • getOthersPresences returns the presences of all other clients.

      Returns { clientID: string; presence: P }[]

    • getPresence returns the presence of the given clientID.

      Parameters

      • clientID: string

      Returns P | undefined

    • getPresenceForTest returns the presence of the given clientID regardless of whether the client is online or not.

      Parameters

      • clientID: string

      Returns P | undefined

    • getPresences returns the presences of online clients.

      Returns { clientID: string; presence: P }[]

    • getRedoStackForTest returns the redo stack for test.

      Returns HistoryOperation<P>[][]

    • getRootCRDT returns the CRDTRoot for testing purposes. This method is intended for internal testing only.

      Returns CRDTRoot

    • getSchemaRules gets the schema rules of this document.

      Returns Rule[]

    • getSelfForTest returns the client that has attached this document.

      Returns { clientID: string; presence: P }

    • getUndoStackForTest returns the undo stack for test.

      Returns HistoryOperation<P>[][]

    • hasLocalChanges returns whether this document has local changes or not.

      Returns boolean

    • hasPresence returns whether the given clientID has a presence or not.

      Parameters

      • clientID: string

      Returns boolean

    • isEnableDevtools returns whether devtools is enabled or not.

      Returns boolean

    • isPresenceDisabled returns the current presence-disabled state of this document. Reflects the server-fixated value once attached; before attach it reflects the local construction option.

      Returns boolean

    • publish triggers an event in this document, which can be received by callback functions from document.subscribe().

      Parameters

      Returns void

    • removeOnlineClient removes the clientID from the online client set.

      Parameters

      • clientID: string

      Returns void

    • setActor sets actor into this document. This is also applied in the local changes the document has.

      Parameters

      • actorID: string

      Returns void

    • setDisableGC records whether this document participates in GC. The client calls this on attach so subsequent applyChange runs use the lamport-only sync path.

      Parameters

      • disableGC: boolean

      Returns void

    • setDisablePresence records the server-fixated presence-disabled state of this document. The client calls this on attach (before applyChangePack) so any subsequent Document.update invocation sees the gating state already settled. Flipping the flag at runtime is supported: the next update honours the new value.

      Parameters

      • disablePresence: boolean

      Returns void

    • setMaxSizePerDocument sets the maximum size of this document.

      Parameters

      • size: number

      Returns void

    • setOnlineClients sets the given online client set.

      Parameters

      • onlineClients: Set<string>

      Returns void

    • setSchemaRules sets the schema rules of this document.

      Parameters

      • rules: Rule[]

      Returns void

    • toSortedJSON returns the sorted JSON encoding of this document.

      Returns string