firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Experimental support for AsyncSequence on Firestore snapshot listeners

Open peterfriese opened this issue 11 months ago • 8 comments

This PR adds support for using Swift's AsyncSequence to listen to changes on Firestore collections and documents.

Here is how to use it:

Listening to updates on a single document

let doc = Firestore.firestore().collection("fruits").document("1uxSAlCvYWmfrXN7rn2s")
for try await fruit in doc.snapshotSequence(Fruit.self) {
  print(fruit.name)
}

Listening to updates on a collection

let collection = Firestore.firestore().collection("fruits")
for try await fruits in collection.snapshotSequence(Fruit.self) {
  print(fruits.count)
}

See Example/FirestoreSample/FirestoreSample/Views/FavouriteFruitsAsyncSequenceView.swift and Example/FirestoreSample/FirestoreSample/Views/FavouriteFruitView.swift for more complete examples how to use this.

peterfriese avatar Jul 05 '23 14:07 peterfriese

1 Warning
:warning: Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by :no_entry_sign: Danger

google-oss-bot avatar Jul 05 '23 14:07 google-oss-bot

Apple API Diff Report

Commit: f9781a01d5852c4c906a94b42f02fe527b5c4750 Last updated: Fri Jul 7 04:30 PDT 2023 View workflow logs & download artifacts


FirebaseFirestoreSwift

Extensions

[ADDED] Query
[ADDED] Query
Swift:
+  public extension Query
+    func snapshotSequence < T > ( _ type : T . Type , includeMetadataChanges : Bool = false ) -> AsyncThrowingStream < [ T ], Error > where T : Decodable
[MODIFIED] DocumentReference
[MODIFIED] DocumentReference
Swift:
+  public extension DocumentReference extension DocumentReference : DocumentIDWrappable
-  extension DocumentReference : DocumentIDWrappable
+    func snapshotSequence < T > ( _ type : T . Type , includeMetadataChanges : Bool = false ) -> AsyncThrowingStream < T , Error > where T : Decodable

github-actions[bot] avatar Jul 05 '23 14:07 github-actions[bot]

Coverage Report 1

Affected Products

  • FirebaseFirestore-iOS-FirebaseFirestore.framework

    Overall coverage changed from 88.11% (cc3ed01) to 88.04% (f9781a0) by -0.07%.

    FilenameBase (cc3ed01)Merge (f9781a0)Diff
    exception.cc84.21%23.68%-60.53%
    leveldb_key.cc98.14%98.82%+0.69%
    leveldb_remote_document_cache.cc96.41%94.61%-1.80%
    ordered_code.cc93.90%94.39%+0.49%
  • FirebaseFirestore-iOS-FirebaseFirestoreSwift.framework

    Overall coverage changed from 40.79% (cc3ed01) to 36.78% (f9781a0) by -4.02%.

    FilenameBase (cc3ed01)Merge (f9781a0)Diff
    DocumentReference+AsyncStream.swift?0.00%?
    Query+AsyncStream.swift?0.00%?

Test Logs

google-oss-bot avatar Jul 05 '23 16:07 google-oss-bot

It could also make sense to have a similar abstraction for a document rather than a query.

mortenbekditlevsen avatar Jul 07 '23 08:07 mortenbekditlevsen

It could also make sense to have a similar abstraction for a document rather than a query.

Good point. Added!

peterfriese avatar Jul 07 '23 10:07 peterfriese

Looks likes you might have had an out of date auth-swift branch. It's been rebased a few times.

paulb777 avatar Jul 15 '23 00:07 paulb777

Please close, merge, or comment. We plan to close stale PRs on November 28, 2023.

paulb777 avatar Nov 14 '23 01:11 paulb777

I'd like to land this in Q4. Will rebase on the latest auth-swift branch.

peterfriese avatar Nov 14 '23 16:11 peterfriese