Skip to content

SyncCoordinator@sheetwrite/core

On this page

Deterministic, transport-neutral optimistic sync. Local rendering is never blocked: changes queue immediately, while hosts explicitly call sendNext or retry to perform network work.

Examples

import { SyncCoordinator, type Grid, type PersistenceAdapter } from "@sheetwrite/core";
async function connect(grid: Grid, adapter: PersistenceAdapter, documentId: string, serverVersion: number) {
await sync.ready();
await sync.flush();
return sync; // Call sync.destroy() before removing the Grid.
}

See also

Members 19

constructor
constructor(grid: Grid, adapter: PersistenceAdapter, options: SyncCoordinatorOptions);
applyVersionedOperation
applyVersionedOperation: (operation: VersionedOperation) => Promise<void>;
destroy
destroy: () => void;
flush
flush: () => Promise<readonly PersistenceCommitResponse[]>;
handleResponse Public for transports that deliver responses independently of send promises.
handleResponse: (response: PersistenceCommitResponse, requestedMutationId?: string) => Promise<void>;
on
on: (listener: SyncListener) => () => void;
pendingCommits
pendingCommits: () => readonly SyncMutationRecord[];
pendingCount
pendingCount: number;
ready Resolves after durable work is restored and every startup commit is visible locally.
ready: () => Promise<void>;
recoverConflict Recover from the outstanding base-version conflict without reloading the document.
recoverConflict: () => Promise<SyncConflictRecovery>;

Recover from the outstanding base-version conflict without reloading the document. This succeeds when the pending work and every server version it did not see change different cells, and neither inserts, deletes, or moves rows or columns: the local Grid then already shows the server result plus the pending work, so recovery applies the missed server versions and moves the pending queue onto the new server version. Call flush afterwards to send it. In every other case nothing changes and the result names the reason; the host then reloads and calls resumeAfterReload.

Examples

import type { SyncCoordinator } from "@sheetwrite/core";
async function recover(sync: SyncCoordinator) {
const result = await sync.recoverConflict();
if (result.status === "recovered") await sync.flush();
// A reload-required result leaves the document unchanged for host recovery.
return result;
}

See also

resumeAfterReload Resume only after the host remounted/reloaded document state and reapplied retained local operations.
resumeAfterReload: (snapshot: WorkbookSnapshot) => Promise<void>;

Resume only after the host remounted/reloaded document state and reapplied retained local operations. No lossy structural merge is attempted here.

retry Explicit retry; the original mutation ID and durable record are retained.
retry: (clientMutationId: string) => Promise<PersistenceCommitResponse | null>;
retryPersistence
retryPersistence: (clientMutationId: string) => Promise<boolean>;
send
send: (clientMutationId: string) => Promise<PersistenceCommitResponse | null>;
sendNext
sendNext: () => Promise<PersistenceCommitResponse | null>;
serverVersion
serverVersion: number;
setOnline Update connectivity. Reconnection drains durable work in order; going offline aborts in-flight requests so retries retain their mutation IDs.
setOnline: (online: boolean) => void;
state
subscribe
subscribe: (source: RemoteOperationSource | AsyncIterable<VersionedOperation>) => () => void

Declaration

View full TypeScript declaration
class SyncCoordinator {
constructor(
grid: Grid,
);
applyVersionedOperation: (operation: VersionedOperation) => Promise<void>;
destroy: () => void;
flush: () => Promise<readonly PersistenceCommitResponse[]>;
handleResponse: (
requestedMutationId?: string,
) => Promise<void>;
on: (listener: SyncListener) => () => void;
pendingCommits: () => readonly SyncMutationRecord[];
pendingCount: number;
ready: () => Promise<void>;
recoverConflict: () => Promise<SyncConflictRecovery>;
resumeAfterReload: (snapshot: WorkbookSnapshot) => Promise<void>;
retry: (
clientMutationId: string,
) => Promise<PersistenceCommitResponse | null>;
retryPersistence: (clientMutationId: string) => Promise<boolean>;
send: (
clientMutationId: string,
) => Promise<PersistenceCommitResponse | null>;
sendNext: () => Promise<PersistenceCommitResponse | null>;
serverVersion: number;
setOnline: (online: boolean) => void;
subscribe: (
source: RemoteOperationSource | AsyncIterable<VersionedOperation>,
) => () => void;
}

Referenced by

Workspace packages depending on @sheetwrite/core

  • @sheetwrite/benchdependency
  • @sheetwrite/docs-startdependency
  • @sheetwrite/reactdependency
  • @sheetwrite/sveltedependency
  • @sheetwrite/vuedependency
  • @sheetwrite/xlsxdependency

Public exports naming SyncCoordinator

  • None.
Documentation