CRDTReplica class

A document on this device: restored from local storage, written back to it, and synced with the other peers.

It opens and closes its parts in the order that keeps the data: the local copy is restored before the client connects, and the client stops before the last writes are flushed. See the README, "Opening a replica".

final replica = await CRDTReplica.open(
  documentId: 'notes',
  storage: () => CRDTSqlite.open('notes.db'),
  sync: (document) => WebSocketClient(
    url: 'ws://localhost:8080',
    document: document,
    author: document.peerId,
  ),
);
final text = CRDTFugueTextHandler(replica.document, 'body');

// ...edit, while the client syncs in the background.

await replica.close();

Properties

client → CRDTSocketClient?
The client that syncs document; null when the replica was opened without sync.
final
document → CRDTDocument
The document. Build the handlers on it.
final
hashCode → int
The hash code for this object.
no setterinherited
isClosed → bool
Whether close has been called.
no setter
persistence → CRDTDocumentPersistence?
What writes document down; null without storage, or when the storage failed to open.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future<void>
Stops the sync, writes what is still waiting, then closes the document and the storage.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

open({required String documentId, FutureOr<CRDTStorageBackend> storage()?, CRDTSocketClient sync(CRDTDocument document)?, void onDocument(CRDTDocument document)?, void onStorageError(Object error, StackTrace stack)?, bool ownsStorage = true}) → Future<CRDTReplica>
Opens documentId on this device and starts to sync it.