The children (registered Collab properties), keyed by name.
This map should only be read, not mutated. It is exposed to subclasses as a convenience for methods that loop over all children.
Internal (this/parent) use only.
This Collab's name, which distinguishes it among its siblings in the tree of Collabs.
Internal (this/parent) use only.
This Collab's parent in the tree of Collabs.
The ambient IRuntime.
Use this to access utilities like IRuntime.replicaID.
The length of the text string.
Returns an iterator for characters (values) in the text string, in order.
Returns a string consisting of the single character
(UTF-16 codepoint) at index
, with behavior
like string.at.
Negative indices are relative to end of the text string, and out-of-bounds indices return undefined.
Internal (parent) use only.
By default, this method returns true if canGC
returns true
on every child. Override to change this behavior.
See Collab.canGC.
Returns a string consisting of the single character
(UTF-16 codepoint) at index
.
Internal (Collab.send) use only.
Sends the given message on behalf of child. In general, this parent is then responsible for delivering the given message to Collab.receive on each replica of child, with guarantees set by the runtime.
Deletes every character in the text string.
Delete count
characters starting at startIndex
, i.e., characters
[startIndex, startIndex + count - 1)
.
All later characters shift to the left,
decreasing their indices by count
.
The number of characters to delete.
Defaults to 1 (delete the character at startIndex
only).
Emits an event, which triggers all the registered event handlers.
See Events for advice on what events to emit.
This is a wrapper around EventEmitter.emit that forces events to extend CollabEvent and also emits an "Any" event.
= true Set to false to skip emitting an "Any" event.
Returns an iterator of [index, position, value] tuples for every character (value) in the text string, in order.
Internal (parent) use only.
By default, this methods calls finalize
on every child.
on every child. Override to change this behavior,
e.g., to add your own finalization steps
(but consider calling super.finalize()
).
Inverse of idOf.
Returns the value at position, or undefined if it is not currently present (hasPosition returns false).
The position currently at index.
Returns whether position is currently present in the list, i.e., its value is present.
Returns a CollabID for the given strict descendant of this parent.
The CollabID may be passed to fromID on any replica of this
parent (but not other parents) to obtain that replica's copy of
descendant
.
Returns the current index of position.
If position is not currently present in the list (hasPosition returns false), then the result depends on searchDir:
Inserts values as a substring at the given index.
All values currently at or after index
shift
to the right, increasing their indices by values.length
.
The insertion index in the range
[0, this.length]
. If this.length
, the values
are appended to the end of the list.
Internal (parent) use only.
Override to load extra state, using savedState
from
saveObject. You can also do post-processing
of child saves, e.g., computing functional
views of child states.
This is called after the children are loaded. Also, this is always called, even if saveObject returned null.
the output of saveObject on a previous saved instance, possibly null.
Registers an event handler that is triggered when the event happens.
Name of the event to listen on.
Callback that handles the event.
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.
Registers an event handler that is triggered only once, the next time the event happens, then unsubscribed.
Name of the event to listen on.
Callback that handles the event.
An "off" function that removes the event handler when called. Use this to remove the handler before the next event (which removes it automatically).
Registers an event handler that is triggered only once, the next time the event happens, then unsubscribed.
An "off" function that removes the event handler when called. Use this to remove the handler before the next event (which removes it automatically).
Internal (parent) use only.
Receives a message sent by send on a local or remote replica of this Collab.
This method processes the message, changes the local state accordingly, and emits events describing the local changes.
This method should make assumptions and ensure consistency guarantees appropriate to its use case. For example, CRDTs may assume eventual, exactly-once, causal-order message delivery, and they must ensure strong eventual consistency.
Typically, you will call this method during the constructor in the style:
this.foo = this.registerCollab("foo", (init) => new FooClass(init, constructor args...));
where readonly foo: FooClass;
is a Collab property.
See Data Modeling for examples.
Registrations must be identical across all replicas.
See also: CRuntime.registerCollab.
A name for this property, unique among
this class's registerCollab
calls.
We recommend using the same name as the property,
but you can also use short strings to reduce
network usage ("", "0", "1", ...).
The registered Collab.
Internal (parent) use only.
Returns saved state describing the current state of this Collab.
The saved state may later be passed to load on a replica of this Collab, possibly in a different collaboration session, with rules set by the runtime. For example, CRuntime allows load to be called only at the beginning of a session, before sending or receiving any messages.
save
may be called at any time, possibly many times while an app
is running. Calling save
should not affect this Collab's
user-visible state.
This method may return null
if
the saved state is trivial; replicas loading the whole document
will then skip calling load on this Collab's replica.
For convenience, the saved state may be expressed as a tree of Uint8Arrays instead of just a single Uint8Array; see [[SaveStateTree]]'s docs.
The saved state, or null if there is no state to save.
Override to save extra state, which is passed to loadObject at the end of load.
Broadcasts a message to other replicas of this Collab. The message will be delivered to all replicas' receive, including locally.
For convenience, the message may be expressed as a stack of
(Uint8Array | string)
,
instead of just a single Uint8Array. This is
useful for parents sending messages on behalf of their children;
see the implementation of CObject for an example.
The message to send, in the form of a stack of Uint8Arrays. Note that this method may mutate it in-place.
A stack of metadata requests. The runtime will use
the union of these when creating the UpdateMeta for receive.
Note that the stack need not align with messageStack
, and this method may mutate
it in place.
Returns a section of this text string, with behavior like string.slice.
Returns the text string as an ordinary string.
Returns an iterator for characters (values) in the text string, in order.
Generated using TypeDoc
A collaborative text string, with the usual behavior for collaborative text editing.
CText is functionally equivalent to a CValueList
<string>
where each value is a single character (UTF-16 codepoint), but with an API more like string.Positions are described in IList.
See also: CValueList, CList.