readDocument method
The document this storage holds, built and handed over, not followed.
For everything that reads and does not write back. Fifty notes in a list cost fifty of these instead of fifty CRDTDocumentPersistences, none of which would ever write anything.
final note = await storage.readDocument();
final title = CRDTFugueTextHandler(note, 'body').value;
Build the handlers on the document it hands back, as above: a handler reads its state from the document whenever it is created.
onDocument runs on the fresh document, before anything is read into it,
for the few things that have to be in place first — the factories a
document needs to resolve nested handlers, say.
peerId is the identity the returned document would write under. It does
not matter for reading, and a new one is minted when it is left out —
pass the stored one from CRDTPeerIdStorage if this document might
write.
Nothing keeps writing this document. An edit made on it stays in memory. Use CRDTStorageBackendDocuments.openDocument for a document that is going to be edited.
Returns without suspending on a storage that reads without suspending, so a list of notes can be built inside one frame.
Implementation
FutureOr<CRDTDocument> readDocument({
PeerId? peerId,
void Function(CRDTDocument document)? onDocument,
}) {
return _read(
storage: this,
peerId: peerId,
onDocument: onDocument,
upTo: null,
);
}