@@ -87,11 +87,11 @@ export class MutationResult {
87
87
*/
88
88
readonly version : SnapshotVersion ,
89
89
/**
90
- * The resulting fields returned from the backend after a
91
- * TransformMutation has been committed. Contains one FieldValue for each
92
- * FieldTransform that was in the mutation.
90
+ * The resulting fields returned from the backend after a mutation
91
+ * containing field transforms has been committed. Contains one FieldValue
92
+ * for each FieldTransform that was in the mutation.
93
93
*
94
- * Will be null if the mutation was not a TransformMutation .
94
+ * Will be null if the mutation did not contain any field transforms .
95
95
*/
96
96
readonly transformResults : Array < ProtoValue | null > | null
97
97
) { }
@@ -178,8 +178,8 @@ export function preconditionIsValidForDocument(
178
178
* Mutations not only act on the value of the document but also its version.
179
179
*
180
180
* For local mutations (mutations that haven't been committed yet), we preserve
181
- * the existing version for Set, Patch, and Transform mutations. For Delete
182
- * mutations, we reset the version to 0.
181
+ * the existing version for Set and Patch mutations. For Delete mutations, we
182
+ * reset the version to 0.
183
183
*
184
184
* Here's the expected transition table.
185
185
*
@@ -191,28 +191,22 @@ export function preconditionIsValidForDocument(
191
191
* PatchMutation Document(v3) Document(v3)
192
192
* PatchMutation NoDocument(v3) NoDocument(v3)
193
193
* PatchMutation null null
194
- * TransformMutation Document(v3) Document(v3)
195
- * TransformMutation NoDocument(v3) NoDocument(v3)
196
- * TransformMutation null null
197
194
* DeleteMutation Document(v3) NoDocument(v0)
198
195
* DeleteMutation NoDocument(v3) NoDocument(v0)
199
196
* DeleteMutation null NoDocument(v0)
200
197
*
201
198
* For acknowledged mutations, we use the updateTime of the WriteResponse as
202
- * the resulting version for Set, Patch, and Transform mutations. As deletes
203
- * have no explicit update time, we use the commitTime of the WriteResponse for
199
+ * the resulting version for Set and Patch mutations. As deletes have no
200
+ * explicit update time, we use the commitTime of the WriteResponse for
204
201
* Delete mutations.
205
202
*
206
203
* If a mutation is acknowledged by the backend but fails the precondition check
207
204
* locally, we return an `UnknownDocument` and rely on Watch to send us the
208
205
* updated version.
209
206
*
210
- * Note that TransformMutations don't create Documents (in the case of being
211
- * applied to a NoDocument), even though they would on the backend. This is
212
- * because the client always combines the TransformMutation with a SetMutation
213
- * or PatchMutation and we only want to apply the transform if the prior
214
- * mutation resulted in a Document (always true for a SetMutation, but not
215
- * necessarily for a PatchMutation).
207
+ * Field transforms are used only with Patch and Set Mutations. We use the
208
+ * `updateTransforms` message to store transforms, rather than the `transforms`s
209
+ * messages.
216
210
*
217
211
* ## Subclassing Notes
218
212
*
@@ -335,13 +329,7 @@ export function extractMutationBaseValue(
335
329
mutation : Mutation ,
336
330
maybeDoc : MaybeDocument | null
337
331
) : ObjectValue | null {
338
- if ( mutation . fieldTransforms !== undefined ) {
339
- return extractTransformMutationBaseValue (
340
- mutation . fieldTransforms ,
341
- maybeDoc
342
- ) ;
343
- }
344
- return null ;
332
+ return extractTransformMutationBaseValue ( mutation . fieldTransforms , maybeDoc ) ;
345
333
}
346
334
347
335
function extractTransformMutationBaseValue (
@@ -489,19 +477,17 @@ function applySetMutationToLocalView(
489
477
}
490
478
491
479
let newData = mutation . value ;
492
- if ( mutation . fieldTransforms ) {
493
- const transformResults = localTransformResults (
494
- mutation . fieldTransforms ,
495
- localWriteTime ,
496
- maybeDoc ,
497
- baseDoc
498
- ) ;
499
- newData = transformObject (
500
- mutation . fieldTransforms ,
501
- newData ,
502
- transformResults
503
- ) ;
504
- }
480
+ const transformResults = localTransformResults (
481
+ mutation . fieldTransforms ,
482
+ localWriteTime ,
483
+ maybeDoc ,
484
+ baseDoc
485
+ ) ;
486
+ newData = transformObject (
487
+ mutation . fieldTransforms ,
488
+ newData ,
489
+ transformResults
490
+ ) ;
505
491
506
492
const version = getPostMutationVersion ( maybeDoc ) ;
507
493
return new Document ( mutation . key , version , newData , {
@@ -623,8 +609,8 @@ function patchObject(mutation: PatchMutation, data: ObjectValue): ObjectValue {
623
609
624
610
/**
625
611
* Creates a list of "transform results" (a transform result is a field value
626
- * representing the result of applying a transform) for use after a
627
- * TransformMutation has been acknowledged by the server.
612
+ * representing the result of applying a transform) for use after a mutation
613
+ * containing transforms has been acknowledged by the server.
628
614
*
629
615
* @param fieldTransforms - The field transforms to apply the result to.
630
616
* @param baseDoc - The document prior to applying this mutation batch.
@@ -664,10 +650,10 @@ function serverTransformResults(
664
650
/**
665
651
* Creates a list of "transform results" (a transform result is a field value
666
652
* representing the result of applying a transform) for use when applying a
667
- * TransformMutation locally.
653
+ * transform locally.
668
654
*
669
655
* @param fieldTransforms - The field transforms to apply the result to.
670
- * @param localWriteTime - The local time of the transform mutation (used to
656
+ * @param localWriteTime - The local time of the mutation (used to
671
657
* generate ServerTimestampValues).
672
658
* @param maybeDoc - The current state of the document after applying all
673
659
* previous mutations.
@@ -689,14 +675,6 @@ function localTransformResults(
689
675
previousValue = maybeDoc . field ( fieldTransform . field ) ;
690
676
}
691
677
692
- if ( previousValue === null && baseDoc instanceof Document ) {
693
- // If the current document does not contain a value for the mutated
694
- // field, use the value that existed before applying this mutation
695
- // batch. This solves an edge case where a PatchMutation clears the
696
- // values in a nested map before the TransformMutation is applied.
697
- previousValue = baseDoc . field ( fieldTransform . field ) ;
698
- }
699
-
700
678
transformResults . push (
701
679
applyTransformOperationToLocalView (
702
680
transform ,
0 commit comments