CRDTTextHandler class
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.
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!"
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 instances for this handler, used in operations.
latefinalinherited
- doc → BaseCRDTDocument
-
The document that owns this handler
finalinherited
- handlerType → String
-
Stable type tag (minification-safe). See Handler.handlerType.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
The unique identifier for
thisconsumerno setteroverride - insertType → OperationType
-
Cached insert type instances for this handler, used in operations.
latefinalinherited
- length → int
-
Gets the length of the text
no setter
- moveType → OperationType
-
Cached move type instances for this handler, used in operations.
latefinalinherited
- operationFactory → OperationFactory
-
The factory function that creates an operation from a payload
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- updateType → OperationType
-
Cached update type instances for this handler, used in operations.
latefinalinherited
- 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 setter
Methods
-
change(
String newText) → void -
Changes the entire text to
newTextusing the Myers diff algorithm. -
compound(
Operation accumulator, Operation current) → Operation? -
During transaction consecutive operations can be compounded.
override
-
delete(
int index, int count) → void -
Deletes
countcharacters starting at the specifiedindex -
getSnapshotState(
) → Uint8List -
Encodes the consumer's current state to a binary blob.
override
-
incrementCachedState(
{required Operation operation, required String state}) → 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 -
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
-
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
-
snapshotVersionVector(
) → VersionVector? -
Returns the version vector of the last snapshot for this consumer.
inherited
-
toString(
) → String -
Returns a string representation of this text
override
-
update(
int index, String text) → void -
Updates the text at the specified
index -
updateCachedState(
String newState) → void -
Replaces the cached state with
newStateand pins it to the current document version. Call this after a full recompute.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited