From 377040afefad2a20a315240a5f5fe6241004a034 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Wed, 17 Jul 2024 02:32:34 +0200 Subject: [PATCH] debugging snapshot conversion --- .../lib/src/v2/firestore_extension.dart | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/app_cv_firestore/lib/src/v2/firestore_extension.dart b/app_cv_firestore/lib/src/v2/firestore_extension.dart index 34f6df6..7dcaf52 100644 --- a/app_cv_firestore/lib/src/v2/firestore_extension.dart +++ b/app_cv_firestore/lib/src/v2/firestore_extension.dart @@ -1,8 +1,8 @@ -import 'dart:async'; - import 'package:tekartik_app_cv_firestore/app_cv_firestore_v2.dart'; import 'package:tekartik_app_cv_firestore/src/v2/cv_document.dart' show CvFirestoreDocumentPrvExt; +import 'package:tekartik_common_utils/common_utils_import.dart'; +import 'package:tekartik_common_utils/foundation/constants.dart'; import 'package:tekartik_common_utils/list_utils.dart'; import 'package:tekartik_firebase_firestore/firestore.dart'; import 'package:tekartik_firebase_firestore/utils/track_changes_support.dart'; @@ -241,19 +241,30 @@ extension CvFirestoreDocumentReferenceExt on DocumentReference { return (await get()).cv(); } + StreamTransformer + _snapshotTransformer() => + StreamTransformer.fromHandlers( + handleData: (data, sink) { + try { + var converted = data.cv(); + sink.add(converted); + // devPrint('cvOnSnapshot $converted'); + } catch (e) { + if (kDebugMode) { + print('cvOnSnapshot.error: $e'); + } + rethrow; + } + }); + /// on snapshots - Stream cvOnSnapshot() => onSnapshot() - .transform(StreamTransformer.fromHandlers(handleData: (data, sink) { - sink.add(data.cv()); - })); + Stream cvOnSnapshot() => + onSnapshot().transform(_snapshotTransformer()); /// on snapshots Stream cvOnSnapshotSupport( {TrackChangesPullOptions? options}) => - onSnapshotSupport(options: options) - .transform(StreamTransformer.fromHandlers(handleData: (data, sink) { - sink.add(data.cv()); - })); + onSnapshotSupport(options: options).transform(_snapshotTransformer()); } /// Easy extension