deleteDoc method
Deletes a document both locally and from Firestore.
Performs an optimistic delete by updating the local state first, then syncing with Firestore. If the remote delete fails, the local state remains updated.
Parameters:
transaction
- Optional transaction for atomic operationsid
- The ID of the document to deletedoNotifyListeners
- Whether to notify listeners of the change
Returns a TurboResponse
indicating success or failure
Implementation
@protected
Future<TurboResponse> deleteDoc({
required String id,
bool doNotifyListeners = true,
Transaction? transaction,
}) async {
try {
log.debug('Deleting doc with id: $id');
deleteLocalDoc(
id: id,
doNotifyListeners: doNotifyListeners,
);
final future = api.deleteDoc(
id: id,
transaction: transaction,
);
final turboResponse = await future;
if (transaction != null) {
turboResponse.throwWhenFail();
}
return turboResponse;
} catch (error, stackTrace) {
if (transaction != null) rethrow;
log.error(
'$error caught while deleting doc',
error: error,
stackTrace: stackTrace,
);
return TurboResponse.fail(error: error);
}
}