C
Replica
testedGeneric op-based CRDT replica: owns a Lamport clock + op log, integrates local and remote ops (with causal buffering and dedup), and exposes deltas for transport-agnostic sync. The domain state lives behind {@link ReplicaHandlers}.
Signature
ts
class Replica<Op extends HasOpId>Type Parameters
Opextends HasOpIdProperties
| Property | Type | Description |
|---|---|---|
sitereadonly | string | — |
versionreadonly | VersionVector | — |
Methods
nextIdNext op id for a locally-generated operation.
ts
nextId(): OpIdReturns
OpIdcommitLocalIntegrate + log a local op, then notify listeners (origin `'local'`).
ts
commitLocal(op: Op): void| Parameter | Type | Description |
|---|---|---|
op | Op | — |
receiveReceive remote ops: dedup, buffer until causally ready, integrate, log, and notify with the ops actually applied. Returns the applied ops (in apply order).
ts
receive(ops: readonly Op[], origin: unknown = 'remote'): Op[]| Parameter | Type | Description |
|---|---|---|
ops | readonly Op[] | — |
origin? | unknown | — |
Returns
Op[]deltaOps a remote replica (described by its version vector) is missing.
ts
delta(remote: VersionVector): Op[]| Parameter | Type | Description |
|---|---|---|
remote | VersionVector | — |
Returns
Op[]onUpdateSubscribe to applied ops (local + remote). Returns an unsubscribe fn.
ts
onUpdate(listener: UpdateListener<Op>): () => void| Parameter | Type | Description |
|---|---|---|
listener | UpdateListener<Op> | — |
Returns
() => void