Skip to content

Instantly share code, notes, and snippets.

@victorbrndls
Last active February 7, 2022 22:59
Show Gist options
  • Save victorbrndls/b62a80c048bc12c98f2b9d6941937466 to your computer and use it in GitHub Desktop.
Save victorbrndls/b62a80c048bc12c98f2b9d6941937466 to your computer and use it in GitHub Desktop.
// LocalDocumentsView.java
Document getDocument(DocumentKey key) {
// 1. Get all mutations for the given document
List<MutationBatch> batches = mutationQueue.getAllMutationBatchesAffectingDocumentKey(key);
return getDocument(key, batches);
}
private Document getDocument(DocumentKey key, List<MutationBatch> inBatches) {
// 2. Fetch the remote version of the given document from the local cache
MutableDocument document = remoteDocumentCache.get(key);
for (MutationBatch batch : inBatches) {
// 3. Apply all mutations to the remote document
batch.applyToLocalView(document);
}
return document; // = RemoteDocument + Active(LocalMutations)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment