CRDTTextHandler class base
CRDT Text
Description
A CRDTText is a text data structure that uses CRDT for conflict-free collaboration. It provides methods for inserting, deleting, and accessing text content.
Index space
Every index and count is measured in runes (Unicode code points). Use RuneOffsets to work with code unit.
Algorithm
Process operations in clock order. Interleaving is handled just using the HLC.
Example
final doc = CRDTDocument();
final text = CRDTTextHandler(doc, 'text');
text..insert(0, 'Hello')..insert(5, ' World!');
print(text.value); // Prints "Hello World!"
- Inheritance
- Mixed-in types
Constructors
- CRDTTextHandler(BaseCRDTDocument doc, String _id)
- Creates a new CRDTText with the given document and ID
Properties
- cachedState → String?
-
The cached state if it still matches the document's current version,
otherwise
null(forcing the host to recompute).no setterinherited - deleteType → OperationType
-
Cached delete type instance for this handler, used in operations.
no setterinherited
- deltaSeq → int
-
The point the stream has reached, without reading value.
no setterinherited
- doc → BaseCRDTDocument
-
The document that owns this handler
finalinherited
- handlerType → String
-
The name of this kind on the wire: it travels in every operation
envelope and in every HandlerRef, so every peer has to spell it the
same way. Make it a constant of your own.
no setterinherited
- hasDeltaListeners → bool
-
Whether anyone is watching this consumer's deltas.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
The unique identifier for
thisconsumerno setteroverride - insertType → OperationType
-
Cached insert type instance for this handler, used in operations.
no setterinherited
- invertible → bool
-
Whether this handler can build the inverse of its own operations.
no setterinherited
- isDeleted → bool
-
Whether this handler was deleted; see BaseCRDTDocument.deleteHandler.
no setterinherited
- length → int
-
Gets the length of the text, in runes
no setter
- minReadableSnapshotBlobVersion → int
-
The oldest blob version this build still reads.
no setterinherited
- moveType → OperationType
-
Cached move type instance for this handler, used in operations.
no setterinherited
- operationDecoders → OperationDecoders
-
The decoders this handler owns, keyed by OperationEnvelope.kind.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- snapshotBlobVersion → int
-
The version of the blob getSnapshotState writes.
no setteroverride
- stateIsOrderIndependent → bool
-
Whether the state is the same whatever the order causally ready
operations are applied in.
no setterinherited
- updateType → OperationType
-
Cached update type instance for this handler, used in operations.
no setterinherited
- useIncrementalCacheUpdate ↔ bool
-
If
false, every applied operation invalidates the cache instead of invoking incrementCachedState. Hosts that have no cheap incremental path may set this tofalseto skip the hook entirely; the defaulttruelets each operation try the incremental path first.getter/setter pairinherited - value → String
-
Gets the current state of the text
no setteroverride
Methods
-
applyDelta(
String base, SequenceDelta< String> delta) → String -
The value
basebecomes oncedeltais applied.override -
change(
String newText) → void -
Changes the entire text to
newTextusing the Myers diff algorithm. -
compound(
Operation accumulator, Operation current) → Operation? -
accumulatorandcurrentfused into one operation, ornullwhen they cannot be.override -
copyValue(
String value) → String -
A copy of
valuethat the caller owns; readSynced goes through it.inherited -
delete(
int index, int count) → void -
Deletes
countrunes starting at the specifiedindex -
getSnapshotState(
) → Uint8List -
Encodes the consumer's current state to a binary blob.
override
-
incrementCachedState(
{required Operation operation, required String state, DeltaSink< Object?> ? sink}) → String? -
Applies
operationtostateand returns the resulting state, ornullto opt out of incremental updates (the cache will be invalidated and recomputed on the next read).override -
insert(
int index, String text) → void -
Inserts
textat the specifiedindex, counted in runes -
invalidateCache(
) → void -
Drops the cached state. The framework calls this automatically when
the consumer's state is no longer guaranteed to match the document
(e.g. external changes imported, snapshot merged, history pruned).
inherited
-
invert(
Operation operation) → List< Operation> -
The operations that undo
operation, against the state as it is beforeoperationis applied. Empty when there is nothing to undo.inherited -
lastSnapshot(
) → Uint8List? -
Returns the last snapshot bytes for this consumer (the value previously
produced by getSnapshotState) or
nullif no snapshot is available.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
operations(
) → List< Operation> -
Returns the Operations required by this consumer to compute its state.
inherited
-
prepareInverse(
Operation operation) → Operation -
operation, an inverse built by invert, made ready to be written now.inherited -
readSnapshotHeader(
Uint8List bytes) → ({int offset, int version}) -
The version at the head of
bytes, and the offset of what follows it.inherited -
readSynced(
) → DeltaSyncPoint< String> -
The current value together with the point of the stream it reflects.
inherited
-
snapshotHeader(
) → BytesBuilder -
A builder holding the head of this handler's snapshot blob.
inherited
-
toString(
) → String -
Returns a string representation of this text
override
-
update(
int index, String text) → void -
Updates the text at the specified
index, counted in runes -
updateCachedState(
String newState) → void -
Replaces the cached state with
newState, valid until the document next drops it. Call this after a full recompute.inherited -
watch(
) → Stream< HandlerUpdate< SequenceDelta< >String> > -
The stream of what happened to this handler, opening with
HandlerReset(ResetCause.initial).inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
spec
→ const HandlerSpec<
CRDTTextHandler> - The kind this handler is.