CRDTFugueTextHandler class

CRDT Text with Fugue implementation

Description

A CRDTFugueText is a text data structure that uses the Fugue algorithm (The Art of the Fugue: Minimizing Interleaving in Collaborative Text Editing) to minimize interleaving. It provides methods for inserting, deleting, and accessing text content.

Algorithm

It uses the Fugue algorithm to minimize interleaving. So even if two users edit the same portion of text the algorithm will minimize the possibility of characters from one user being interleaved with the characters from the other user.

Example

final doc = CRDTDocument();
final text = CRDTFugueTextHandler(doc, 'text');
text..insert(0, 'Hello')..insert(5, ' World');
print(text.value); // Prints ["Hello"]
Inheritance

Constructors

CRDTFugueTextHandler(BaseCRDTDocument doc, String _id)
Constructor that initializes a new Fugue text handler

Properties

cachedState FugueTextState?
Returns the cached state
no setterinherited
deleteType OperationType
Cached delete type instances for this handler, used in operations.
latefinalinherited
doc BaseCRDTDocument
The document that owns this handler
finalinherited
hashCode int
The hash code for this object.
no setterinherited
id String
The unique identifier for this consumer
no setteroverride
insertType OperationType
Cached insert type instances for this handler, used in operations.
latefinalinherited
length int
Gets the length of the text
no setter
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
Whether to use incremental cache update
getter/setter pairinherited
value String
Gets the current value of the text
no setter

Methods

change(String newText) → void
Changes the entire text to newText using the Myers diff algorithm.
compound(Operation accumulator, Operation current) Operation?
During transaction consecutive operations can be compounded.
inherited
delete(int index, int count) → void
Deletes count characters starting from position index
getSnapshotState() Uint8List
Encodes the consumer's current state to a binary blob.
override
incrementCachedState({required Operation operation, required FugueTextState state}) FugueTextState?
When the document receives an operation and a change is applied anyone using CacheableStateProvider is allowed to increment the cached state.
override
insert(int index, String text) → void
Inserts text at position index
invalidateCache() → void
Invalidates the cached state
inherited
lastSnapshot() Uint8List?
Returns the last snapshot bytes for this consumer (the value previously produced by getSnapshotState) or null if 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 text representation of this handler
override
update(int index, String text) → void
Updates the text at position index
updateCachedState(FugueTextState newState) → void
Updates the cached state
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited