Skip to content

Commit 8f62706

Browse files
author
Greg Soltis
authored
Make disable internal sync and update notes about OnlineState (#380)
* Make disableNetworkInternal explicitly synchronous * Add notes to OnlineState type * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: Prettier Code Styling * Update comments per Michael's suggestions * More fixup
1 parent 2fa51d3 commit 8f62706

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/firestore/src/core/types.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ export type TargetId = number;
3030
// they're strings. We should probably (de-)serialize to a common internal type.
3131
export type ProtoByteString = Uint8Array | string;
3232

33-
/** Describes the online state of the Firestore client */
33+
/**
34+
* Describes the online state of the Firestore client. Note that this does not
35+
* indicate whether or not the remote store is trying to connect or not. This is
36+
* primarily used by the View / EventManager code to change their behavior while
37+
* offline (e.g. get() calls shouldn't wait for data from the server and
38+
* snapshot events should set metadata.isFromCache=true).
39+
*/
3440
export enum OnlineState {
3541
/**
3642
* The Firestore client is in an unknown online state. This means the client
3743
* is either not actively trying to establish a connection or it is currently
3844
* trying to establish a connection, but it has not succeeded or failed yet.
45+
* Higher-level components should not operate in offline mode.
3946
*/
4047
Unknown,
4148

@@ -47,9 +54,9 @@ export enum OnlineState {
4754
Healthy,
4855

4956
/**
50-
* The client considers itself offline. It is either trying to establish a
51-
* connection but failing, or it has been explicitly marked offline via a call
52-
* to disableNetwork().
57+
* The client is either trying to establish a connection but failing, or it
58+
* has been explicitly marked offline via a call to disableNetwork().
59+
* Higher-level components should operate in offline mode.
5360
*/
5461
Failed
5562
}

packages/firestore/src/remote/remote_store.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,15 @@ export class RemoteStore {
243243
*/
244244
disableNetwork(): Promise<void> {
245245
// Set the OnlineState to failed so get()'s return from cache, etc.
246-
return this.disableNetworkInternal(OnlineState.Failed);
246+
this.disableNetworkInternal(OnlineState.Failed);
247+
return Promise.resolve();
247248
}
248249

249250
/**
250251
* Disables the network, setting the OnlineState to the specified
251252
* targetOnlineState.
252253
*/
253-
private disableNetworkInternal(
254-
targetOnlineState: OnlineState
255-
): Promise<void> {
254+
private disableNetworkInternal(targetOnlineState: OnlineState): void {
256255
// NOTE: We're guaranteed not to get any further events from these streams (not even a close
257256
// event).
258257
this.watchStream.stop();
@@ -265,8 +264,6 @@ export class RemoteStore {
265264
this.watchStream = null;
266265

267266
this.updateOnlineState(targetOnlineState);
268-
269-
return Promise.resolve();
270267
}
271268

272269
shutdown(): Promise<void> {

0 commit comments

Comments
 (0)