Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Firestore/Example/Tests/Core/FSTEventManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ - (void)testWillForwardOnlineStateChanges {
FSTQueryListener *fakeListener = OCMClassMock([FSTQueryListener class]);
NSMutableArray *events = [NSMutableArray array];
OCMStub([fakeListener query]).andReturn(query);
OCMStub([fakeListener clientDidChangeOnlineState:FSTOnlineStateUnknown])
OCMStub([fakeListener applyOnlineStateChange:FSTOnlineStateUnknown])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to follow Objective-C's naming convention as it does not use a suffix that describes the argument. I'm going to suggest applyChangeForOnlineState, but I'm certain that there are better options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to applyChangedOnlineState: per offline discussion.

.andDo(^(NSInvocation *invocation) {
[events addObject:@(FSTOnlineStateUnknown)];
});
OCMStub([fakeListener clientDidChangeOnlineState:FSTOnlineStateHealthy])
OCMStub([fakeListener applyOnlineStateChange:FSTOnlineStateHealthy])
.andDo(^(NSInvocation *invocation) {
[events addObject:@(FSTOnlineStateHealthy)];
});
Expand All @@ -154,7 +154,7 @@ - (void)testWillForwardOnlineStateChanges {

[eventManager addListener:fakeListener];
XCTAssertEqualObjects(events, @[ @(FSTOnlineStateUnknown) ]);
[eventManager watchStreamDidChangeOnlineState:FSTOnlineStateHealthy];
[eventManager applyOnlineStateChange:FSTOnlineStateHealthy];
XCTAssertEqualObjects(events, (@[ @(FSTOnlineStateUnknown), @(FSTOnlineStateHealthy) ]));
}

Expand Down
20 changes: 10 additions & 10 deletions Firestore/Example/Tests/Core/FSTQueryListenerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ - (void)testWillWaitForSyncIfOnline {
[FSTTargetChange changeWithDocuments:@[ doc1, doc2 ]
currentStatusUpdate:FSTCurrentStatusUpdateMarkCurrent]);

[listener clientDidChangeOnlineState:FSTOnlineStateHealthy]; // no event
[listener applyOnlineStateChange:FSTOnlineStateHealthy]; // no event
[listener queryDidChangeViewSnapshot:snap1];
[listener clientDidChangeOnlineState:FSTOnlineStateUnknown];
[listener clientDidChangeOnlineState:FSTOnlineStateHealthy];
[listener applyOnlineStateChange:FSTOnlineStateUnknown];
[listener applyOnlineStateChange:FSTOnlineStateHealthy];
[listener queryDidChangeViewSnapshot:snap2];
[listener queryDidChangeViewSnapshot:snap3];

Expand Down Expand Up @@ -379,11 +379,11 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil);

[listener clientDidChangeOnlineState:FSTOnlineStateHealthy]; // no event
[listener applyOnlineStateChange:FSTOnlineStateHealthy]; // no event
[listener queryDidChangeViewSnapshot:snap1]; // no event
[listener clientDidChangeOnlineState:FSTOnlineStateFailed]; // event
[listener clientDidChangeOnlineState:FSTOnlineStateUnknown]; // no event
[listener clientDidChangeOnlineState:FSTOnlineStateFailed]; // no event
[listener applyOnlineStateChange:FSTOnlineStateFailed]; // event
[listener applyOnlineStateChange:FSTOnlineStateUnknown]; // no event
[listener applyOnlineStateChange:FSTOnlineStateFailed]; // no event
[listener queryDidChangeViewSnapshot:snap2]; // another event

FSTDocumentViewChange *change1 =
Expand Down Expand Up @@ -419,9 +419,9 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);

[listener clientDidChangeOnlineState:FSTOnlineStateHealthy]; // no event
[listener applyOnlineStateChange:FSTOnlineStateHealthy]; // no event
[listener queryDidChangeViewSnapshot:snap1]; // no event
[listener clientDidChangeOnlineState:FSTOnlineStateFailed]; // event
[listener applyOnlineStateChange:FSTOnlineStateFailed]; // event

FSTViewSnapshot *expectedSnap = [[FSTViewSnapshot alloc]
initWithQuery:query
Expand All @@ -445,7 +445,7 @@ - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);

[listener clientDidChangeOnlineState:FSTOnlineStateFailed]; // no event
[listener applyOnlineStateChange:FSTOnlineStateFailed]; // no event
[listener queryDidChangeViewSnapshot:snap1]; // event

FSTViewSnapshot *expectedSnap = [[FSTViewSnapshot alloc]
Expand Down
4 changes: 2 additions & 2 deletions Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ - (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
return self;
}

- (void)watchStreamDidChangeOnlineState:(FSTOnlineState)onlineState {
- (void)applyOnlineStateChange:(FSTOnlineState)onlineState {
[self.syncEngine applyOnlineStateChange:onlineState];
[self.eventManager watchStreamDidChangeOnlineState:onlineState];
[self.eventManager applyOnlineStateChange:onlineState];
}

- (void)start {
Expand Down
2 changes: 1 addition & 1 deletion Firestore/Source/Core/FSTEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN

- (void)queryDidChangeViewSnapshot:(FSTViewSnapshot *)snapshot;
- (void)queryDidError:(NSError *)error;
- (void)clientDidChangeOnlineState:(FSTOnlineState)onlineState;
- (void)applyOnlineStateChange:(FSTOnlineState)onlineState;

@property(nonatomic, strong, readonly) FSTQuery *query;

Expand Down
8 changes: 4 additions & 4 deletions Firestore/Source/Core/FSTEventManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ - (void)queryDidError:(NSError *)error {
self.viewSnapshotHandler(nil, error);
}

- (void)clientDidChangeOnlineState:(FSTOnlineState)onlineState {
- (void)applyOnlineStateChange:(FSTOnlineState)onlineState {
self.onlineState = onlineState;
if (self.snapshot && !self.raisedInitialEvent &&
[self shouldRaiseInitialEventForSnapshot:self.snapshot onlineState:onlineState]) {
Expand Down Expand Up @@ -268,7 +268,7 @@ - (FSTTargetID)addListener:(FSTQueryListener *)listener {
}
[queryInfo.listeners addObject:listener];

[listener clientDidChangeOnlineState:self.onlineState];
[listener applyOnlineStateChange:self.onlineState];

if (queryInfo.viewSnapshot) {
[listener queryDidChangeViewSnapshot:queryInfo.viewSnapshot];
Expand Down Expand Up @@ -321,11 +321,11 @@ - (void)handleError:(NSError *)error forQuery:(FSTQuery *)query {
[self.queries removeObjectForKey:query];
}

- (void)watchStreamDidChangeOnlineState:(FSTOnlineState)onlineState {
- (void)applyOnlineStateChange:(FSTOnlineState)onlineState {
self.onlineState = onlineState;
for (FSTQueryListenersInfo *info in self.queries.objectEnumerator) {
for (FSTQueryListener *listener in info.listeners) {
[listener clientDidChangeOnlineState:onlineState];
[listener applyOnlineStateChange:onlineState];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Firestore/Source/Core/FSTFirestoreClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ - (void)userDidChange:(FSTUser *)user {
[self.syncEngine userDidChange:user];
}

- (void)watchStreamDidChangeOnlineState:(FSTOnlineState)onlineState {
- (void)applyOnlineStateChange:(FSTOnlineState)onlineState {
[self.syncEngine applyOnlineStateChange:onlineState];
[self.eventManager watchStreamDidChangeOnlineState:onlineState];
[self.eventManager applyOnlineStateChange:onlineState];
}

- (void)disableNetworkWithCompletion:(nullable FSTVoidErrorBlock)completion {
Expand Down
2 changes: 1 addition & 1 deletion Firestore/Source/Remote/FSTRemoteStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol FSTOnlineStateDelegate <NSObject>

/** Called whenever the online state of the watch stream changes */
- (void)watchStreamDidChangeOnlineState:(FSTOnlineState)onlineState;
- (void)applyOnlineStateChange:(FSTOnlineState)onlineState;

@end

Expand Down
2 changes: 1 addition & 1 deletion Firestore/Source/Remote/FSTRemoteStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ - (void)updateOnlineState:(FSTOnlineState)newState {
// Update and broadcast the new state.
if (newState != self.watchStreamOnlineState) {
self.watchStreamOnlineState = newState;
[self.onlineStateDelegate watchStreamDidChangeOnlineState:newState];
[self.onlineStateDelegate applyOnlineStateChange:newState];
}
}

Expand Down