deleteDoc method

  1. @protected
Future<TurboResponse> deleteDoc({
  1. required String id,
  2. bool doNotifyListeners = true,
  3. Transaction? transaction,
})

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 operations
  • id - The ID of the document to delete
  • doNotifyListeners - 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);
  }
}