|
24 | 24 | #import "Firestore/Source/Core/FSTQuery.h"
|
25 | 25 | #import "Firestore/Source/Core/FSTView.h"
|
26 | 26 | #import "Firestore/Source/Model/FSTDocument.h"
|
27 |
| -#import "Firestore/Source/Util/FSTAsyncQueryListener.h" |
28 | 27 |
|
29 | 28 | #import "Firestore/Example/Tests/Util/FSTHelpers.h"
|
30 | 29 |
|
31 | 30 | #include "Firestore/core/include/firebase/firestore/firestore_errors.h"
|
| 31 | +#include "Firestore/core/src/firebase/firestore/core/event_listener.h" |
32 | 32 | #include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
|
33 | 33 | #include "Firestore/core/src/firebase/firestore/model/document_set.h"
|
34 | 34 | #include "Firestore/core/src/firebase/firestore/model/types.h"
|
|
40 | 40 | #include "Firestore/core/test/firebase/firestore/testutil/xcgmock.h"
|
41 | 41 |
|
42 | 42 | using firebase::firestore::FirestoreErrorCode;
|
| 43 | +using firebase::firestore::core::AsyncEventListener; |
| 44 | +using firebase::firestore::core::EventListener; |
43 | 45 | using firebase::firestore::core::DocumentViewChange;
|
| 46 | +using firebase::firestore::core::EventListener; |
44 | 47 | using firebase::firestore::core::ListenOptions;
|
45 | 48 | using firebase::firestore::core::ViewSnapshot;
|
46 |
| -using firebase::firestore::core::ViewSnapshotHandler; |
47 | 49 | using firebase::firestore::model::DocumentKeySet;
|
48 | 50 | using firebase::firestore::model::DocumentSet;
|
49 | 51 | using firebase::firestore::model::OnlineState;
|
@@ -72,10 +74,11 @@ ViewSnapshot ExcludingMetadataChanges(const ViewSnapshot &snapshot) {
|
72 | 74 | };
|
73 | 75 | }
|
74 | 76 |
|
75 |
| -ViewSnapshotHandler Accumulating(std::vector<ViewSnapshot> *values) { |
76 |
| - return [values](const StatusOr<ViewSnapshot> &maybe_snapshot) { |
77 |
| - values->push_back(maybe_snapshot.ValueOrDie()); |
78 |
| - }; |
| 77 | +ViewSnapshot::Listener Accumulating(std::vector<ViewSnapshot> *values) { |
| 78 | + return EventListener<ViewSnapshot>::Create( |
| 79 | + [values](const StatusOr<ViewSnapshot> &maybe_snapshot) { |
| 80 | + values->push_back(maybe_snapshot.ValueOrDie()); |
| 81 | + }); |
79 | 82 | }
|
80 | 83 |
|
81 | 84 | } // namespace
|
@@ -166,26 +169,26 @@ - (void)testRaisesEventForEmptyCollectionAfterSync {
|
166 | 169 | }
|
167 | 170 |
|
168 | 171 | - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
|
169 |
| - __block std::vector<ViewSnapshot> accum; |
| 172 | + std::vector<ViewSnapshot> accum; |
170 | 173 |
|
171 | 174 | FSTQuery *query = FSTTestQuery("rooms/Eros");
|
172 | 175 | FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
|
173 | 176 | FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, FSTDocumentStateSynced);
|
174 | 177 |
|
175 |
| - __block FSTAsyncQueryListener *listener = [[FSTAsyncQueryListener alloc] |
176 |
| - initWithExecutor:_executor.get() |
177 |
| - snapshotHandler:^(const StatusOr<ViewSnapshot> &maybe_snapshot) { |
178 |
| - accum.push_back(maybe_snapshot.ValueOrDie()); |
179 |
| - [listener mute]; |
180 |
| - }]; |
| 178 | + std::shared_ptr<AsyncEventListener<ViewSnapshot>> listener = |
| 179 | + AsyncEventListener<ViewSnapshot>::Create( |
| 180 | + _executor.get(), EventListener<ViewSnapshot>::Create( |
| 181 | + [&accum, &listener](const StatusOr<ViewSnapshot> &maybe_snapshot) { |
| 182 | + accum.push_back(maybe_snapshot.ValueOrDie()); |
| 183 | + listener->Mute(); |
| 184 | + })); |
181 | 185 |
|
182 | 186 | FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
|
183 | 187 | ViewSnapshot viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], absl::nullopt).value();
|
184 | 188 | ViewSnapshot viewSnapshot2 = FSTTestApplyChanges(view, @[ doc2 ], absl::nullopt).value();
|
185 | 189 |
|
186 |
| - ViewSnapshotHandler handler = listener.asyncSnapshotHandler; |
187 |
| - handler(viewSnapshot1); |
188 |
| - handler(viewSnapshot2); |
| 190 | + listener->OnEvent(viewSnapshot1); |
| 191 | + listener->OnEvent(viewSnapshot2); |
189 | 192 |
|
190 | 193 | // Drain queue
|
191 | 194 | XCTestExpectation *expectation = [self expectationWithDescription:@"Queue drained"];
|
|
0 commit comments