CRDTDocumentPersistence class

Keeps a CRDTDocument on disk as it changes.

open reads the stored document back. Then every change, snapshot and prune the document reports on CRDTDocument.events is written down. See the README, "How it works".

final persistence = await CRDTDocumentPersistence.open(document, storage);
text.insert(0, 'Hello');
await persistence.dispose(); // writes what is still waiting

Properties

hashCode → int
The hash code for this object.
no setterinherited
hasUnwrittenChanges → bool
Whether changes, snapshots or prunes still wait to be written.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
storage → CRDTDocumentStorage
Where the document is kept.
final
storedVersion → VersionVector
The version of the document the storage brings back after a crash. It only grows.
no setter

Methods

compact() → Future<Snapshot>
Snapshots the document, prunes the history the snapshot covers, and waits for both to reach the disk.
dispose() → Future<void>
Stops following the document and writes what is still waiting.
flush({bool throwOnError = false}) → Future<void>
Writes what is waiting now, and waits for it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
whenStored(VersionVector version) → Future<void>
Completes once storedVersion covers version.

Operators

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

Static Methods

open(CRDTDocument document, CRDTDocumentStorage storage, {Duration writeDelay = const Duration(milliseconds: 250), int? compactAfter, int? keepSnapshots = 1, void onError(Object error, StackTrace stack)?}) → Future<CRDTDocumentPersistence>
Reads the stored document into document, then writes down what it reports.
openSync(CRDTDocument document, CRDTDocumentStorage storage, {Duration writeDelay = const Duration(milliseconds: 250), int? compactAfter, int? keepSnapshots = 1, void onError(Object error, StackTrace stack)?}) → CRDTDocumentPersistence
open for a storage that reads without suspending: the document is already restored when this returns.