modify<T> method
Future<NimbostratusDocumentSnapshot<T?> >
modify<T>(
- DocumentReference<
T> ref, - T modifyFn(
- T? currentValue
- WritePolicy writePolicy = WritePolicy.serverFirst,
- ToFirestore<
T> ? toFirestore, - NimbostratusFromFirestore<
T> ? fromFirestore,
Implementation
Future<NimbostratusDocumentSnapshot<T?>> modify<T>(
DocumentReference<T> ref,
T Function(T? currentValue) modifyFn, {
WritePolicy writePolicy = WritePolicy.serverFirst,
ToFirestore<T>? toFirestore,
NimbostratusFromFirestore<T>? fromFirestore,
}) async {
final snap = await _modify<T>(
ref,
modifyFn,
writePolicy: writePolicy,
toFirestore: toFirestore,
batch: _batch,
fromFirestore: fromFirestore,
/// A [WritePolicy.serverFirst] is not optimistic as it waits for the server response. Otherwise
/// the batch update will be optimistic since both [WritePolicy.cacheOnly] and [WritePolicy.cacheAndServer]
/// will optimistically write to the cache first.
isOptimistic: writePolicy != WritePolicy.serverFirst,
);
// The returned snap may not be optimistic if for example, the optimistic update we're trying to perform is already the current value of the
// document, in which case it won't re-emit any new value.
if (snap.isOptimistic) {
_batchOpimisticSnapshots.add(snap);
}
return snap;
}