Constructs an AbstractDoc.
See DocOptions.
The CRuntime for this document's Collabs.
Use its CRuntime.registerCollab method to register your "global variable" Collabs. Typically, you will do so in your constructor.
An ID that uniquely identifies this replica among all connected replicas.
See CRuntime.replicaID.
Delivers remotes updates (receive/load calls) in a batch, so that only a single "Change" event is emitted for the entire batch.
f()
is called immediately, then if it delivered any remote updates,
a single "Change" event is emitted.
That way, "Change" listeners know that they only need
to refresh the display once at the end, instead of once per receive/load
call.
Notes:
See also: transact, a similar method for local operations.
Emits an event, which triggers all the registered event handlers.
Event handlers are called in the order they are added. Errors in
event handlers are captured and logged (with console.error
),
not propagated to the caller.
Name of the event to emit.
Event object to pass to the event handlers.
Inverse of idOf.
Returns a CollabID for the given Collab.
The CollabID may be passed to fromID on any replica of this
AbstractDoc to obtain that replica's copy of collab
.
A Collab that belongs to this AbstractDoc.
Loads saved state. The saved state must be from a call to save on an AbstractDoc that is a replica of this one (i.e., it has the same "schema").
The local Collabs merge in the saved state, change the local state accordingly, and emit events describing the local changes.
Calling load is roughly equivalent to calling receive on every message that influenced the saved state (skipping already-received messages), but it is typically much more efficient.
Saved state from another replica's save call.
Optionally, a value to use as the "Update" event's SavedStateEvent.caller field. A caller can use that field to distinguish its own updates from updates delivered by other sources.
Registers an event handler that is triggered when the event happens.
Name of the event to listen on.
Callback that handles the event.
If true, the event handler is triggered at most once (the next time the event happens), then unsubscribed.
An "off" function that removes the event handler when called.
Registers an event handler that is triggered when the event happens.
An "off" function that removes the event handler when called.
Receives a message from another replica's DocEventsRecord.Send event. The message's sender must be an AbstractDoc that is a replica of this one (i.e., it has the same "schema").
The local Collabs process the message, change the local state accordingly, and emit events describing the local changes.
Messages from other replicas should be received eventually and at-least-once. Arbitrary delays, duplicates, reordering, and delivery of (redundant) messages from this replica are acceptable. Two replicas will be in the same state once they have the same set of received (or sent) messages.
Optionally, a value to use as the "Update" event's MessageEvent.caller field. A caller can use that field to distinguish its own updates from updates delivered by other sources.
Returns saved state describing the current state of this document.
The saved state may later be passed to load on a replica of this AbstractDoc, possibly in a different collaboration session. That is equivalent to delivering all messages that this document has already sent or received.
Wraps f
's operations in a
transaction.
f()
is called immediately, then if it performed any local Collab operations,
their transaction is ended (emitting "Send", "Update", and "Change" events).
Notes:
transact
call use the constructor's
DocOptions.autoTransactions option.transact
calls (possibly due to
DocOptions.autoTransactions), only the outermost one matters.See also: batchRemoteUpdates, a similar method for remote updates.
The vector clock for our current state, mapping each senderID to the number of applied transactions from that senderID.
Our current state includes precisely the transactions
with ID (senderID, senderCounter)
where
senderCounter <= (vectorClock.get(senderID) ?? 0)
.
Generated using TypeDoc
Base class for an encapsulated Collabs document, which wraps its CRuntime and registered Collabs in a single object.
To get started with AbstractDoc, see Documents - Using AbstractDoc.
AbstractDoc is network- and storage-agnostic. By itself, it does not connect to remote collaborators or persistent storage. To easily set up networking and storage, configure Providers. Or, manually manage updates using the methods in this class; see Updates and Sync.