Skip to content

Commit bd5b4d8

Browse files
committed
fix setHasLocalMutations, and port more tests.
1 parent 143d1c0 commit bd5b4d8

File tree

4 files changed

+487
-26
lines changed

4 files changed

+487
-26
lines changed

packages/firestore/src/model/document.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,8 @@ export class MutableDocument implements Document {
285285
}
286286

287287
setHasLocalMutations(): MutableDocument {
288-
debugAssert(
289-
this.isFoundDocument(),
290-
'Only found documents can have local mutations'
291-
);
292288
this.documentState = DocumentState.HAS_LOCAL_MUTATIONS;
289+
this.version = SnapshotVersion.min();
293290
return this;
294291
}
295292

packages/firestore/src/model/mutation.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,6 @@ function mutationVerifyKeyMatches(
424424
);
425425
}
426426

427-
/**
428-
* Returns the version from the given document for use as the result of a
429-
* mutation. Mutations are defined to return the version of the base document
430-
* only if it is an existing document. Deleted and unknown documents have a
431-
* post-mutation version of SnapshotVersion.min().
432-
*/
433-
function getPostMutationVersion(document: MutableDocument): SnapshotVersion {
434-
return document.isFoundDocument() ? document.version : SnapshotVersion.min();
435-
}
436-
437427
/**
438428
* A mutation that creates or replaces the document at the given key with the
439429
* object value contents.
@@ -491,7 +481,7 @@ function setMutationApplyToLocalView(
491481
);
492482
newData.setAll(transformResults);
493483
document
494-
.convertToFoundDocument(getPostMutationVersion(document), newData)
484+
.convertToFoundDocument(document.version, newData)
495485
.setHasLocalMutations();
496486
// SetMutation overwrites all fields.
497487
return null;
@@ -570,7 +560,7 @@ function patchMutationApplyToLocalView(
570560
newData.setAll(getPatch(mutation));
571561
newData.setAll(transformResults);
572562
document
573-
.convertToFoundDocument(getPostMutationVersion(document), newData)
563+
.convertToFoundDocument(document.version, newData)
574564
.setHasLocalMutations();
575565

576566
if (previousMask === null) {
@@ -709,9 +699,7 @@ function deleteMutationApplyToLocalView(
709699
'Can only apply mutation to document with same key'
710700
);
711701
if (preconditionIsValidForDocument(mutation.precondition, document)) {
712-
// We don't call `setHasLocalMutations()` since we want to be backwards
713-
// compatible with the existing SDK behavior.
714-
document.convertToNoDocument(SnapshotVersion.min());
702+
document.convertToNoDocument(document.version).setHasLocalMutations();
715703
return null;
716704
}
717705
return previousMask;

0 commit comments

Comments
 (0)