Skip to content

Commit 6495dca

Browse files
author
Brian Chen
authored
Move snapshotsInSync to public (#3942)
1 parent 4c19a13 commit 6495dca

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

Firestore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Unreleased
2+
- [feature] Added an `addSnapshotsInSyncListener()` method to
3+
`FIRFirestore` that notifies you when all your snapshot listeners are
4+
in sync with each other.
25

36
# v1.5.1
47
- [fixed] Fixed a memory access error discovered using the sanitizers in Xcode

Firestore/Source/API/FIRFirestore+Internal.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
#import "FIRFirestore.h"
18-
#import "FIRListenerRegistration.h"
1918

2019
#include <memory>
2120
#include <string>
@@ -69,26 +68,6 @@ NS_ASSUME_NONNULL_BEGIN
6968

7069
- (const std::shared_ptr<util::AsyncQueue> &)workerQueue;
7170

72-
/**
73-
* Attaches a listener for a snapshots-in-sync event. Server-generated
74-
* updates and local changes can affect multiple snapshot listeners.
75-
* The snapshots-in-sync event indicates that all listeners affected by
76-
* a given change have fired.
77-
*
78-
* NOTE: The snapshots-in-sync event only indicates that listeners are
79-
* in sync with each other, but does not relate to whether those
80-
* snapshots are in sync with the server. Use SnapshotMetadata in the
81-
* individual listeners to determine if a snapshot is from the cache or
82-
* the server.
83-
*
84-
* @param listener A callback to be called every time all snapshot
85-
* listeners are in sync with each other.
86-
* @return A FIRListenerRegistration object that can be used to remove the
87-
* listener.
88-
*/
89-
- (id<FIRListenerRegistration>)addSnapshotsInSyncListener:(void (^)(void))listener
90-
NS_SWIFT_NAME(addSnapshotsInSyncListener(_:));
91-
9271
@property(nonatomic, assign, readonly) std::shared_ptr<api::Firestore> wrapped;
9372

9473
@property(nonatomic, assign, readonly) const model::DatabaseId &databaseID;

Firestore/Source/Public/FIRFirestore.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
#import "FIRListenerRegistration.h"
20+
1921
@class FIRApp;
2022
@class FIRCollectionReference;
2123
@class FIRDocumentReference;
@@ -208,6 +210,26 @@ NS_SWIFT_NAME(Firestore)
208210
*/
209211
- (void)waitForPendingWritesWithCompletion:(void (^)(NSError *_Nullable error))completion;
210212

213+
/**
214+
* Attaches a listener for a snapshots-in-sync event. Server-generated
215+
* updates and local changes can affect multiple snapshot listeners.
216+
* The snapshots-in-sync event indicates that all listeners affected by
217+
* a given change have fired.
218+
*
219+
* NOTE: The snapshots-in-sync event only indicates that listeners are
220+
* in sync with each other, but does not relate to whether those
221+
* snapshots are in sync with the server. Use SnapshotMetadata in the
222+
* individual listeners to determine if a snapshot is from the cache or
223+
* the server.
224+
*
225+
* @param listener A callback to be called every time all snapshot
226+
* listeners are in sync with each other.
227+
* @return A FIRListenerRegistration object that can be used to remove the
228+
* listener.
229+
*/
230+
- (id<FIRListenerRegistration>)addSnapshotsInSyncListener:(void (^)(void))listener
231+
NS_SWIFT_NAME(addSnapshotsInSyncListener(_:));
232+
211233
#pragma mark - Terminating
212234

213235
/**

Firestore/Swift/Tests/API/BasicCompileTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func main() {
6666

6767
waitForPendingWrites(database: db)
6868

69+
addSnapshotsInSyncListener(database: db)
70+
6971
terminateDb(database: db)
7072
}
7173

@@ -462,6 +464,13 @@ func waitForPendingWrites(database db: Firestore) {
462464
}
463465
}
464466

467+
func addSnapshotsInSyncListener(database db: Firestore) {
468+
let listener = db.addSnapshotsInSyncListener {}
469+
470+
// Unsubscribe
471+
listener.remove()
472+
}
473+
465474
func terminateDb(database db: Firestore) {
466475
db.terminate { error in
467476
if let e = error {

0 commit comments

Comments
 (0)