Skip to content

Make disable internal sync and update notes about OnlineState #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
15 changes: 11 additions & 4 deletions packages/firestore/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ export type TargetId = number;
// they're strings. We should probably (de-)serialize to a common internal type.
export type ProtoByteString = Uint8Array | string;

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

Expand All @@ -47,9 +54,9 @@ export enum OnlineState {
Healthy,

/**
* The client considers itself offline. It is either trying to establish a
* connection but failing, or it has been explicitly marked offline via a call
* to disableNetwork().
* The client is either trying to establish a connection but failing, or it
* has been explicitly marked offline via a call to disableNetwork().
* Higher-level components should not operate in offline mode.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the opposite of correct now. :-P

Copy link
Author

Choose a reason for hiding this comment

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

Oops, yeah, cut-and-paste fail.

*/
Failed
}
9 changes: 3 additions & 6 deletions packages/firestore/src/remote/remote_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,15 @@ export class RemoteStore {
*/
disableNetwork(): Promise<void> {
// Set the OnlineState to failed so get()'s return from cache, etc.
return this.disableNetworkInternal(OnlineState.Failed);
this.disableNetworkInternal(OnlineState.Failed);
return Promise.resolve();
}

/**
* Disables the network, setting the OnlineState to the specified
* targetOnlineState.
*/
private disableNetworkInternal(
targetOnlineState: OnlineState
): Promise<void> {
private disableNetworkInternal(targetOnlineState: OnlineState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explicitly declare the return type to be void now?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

// NOTE: We're guaranteed not to get any further events from these streams (not even a close
// event).
this.watchStream.stop();
Expand All @@ -265,8 +264,6 @@ export class RemoteStore {
this.watchStream = null;

this.updateOnlineState(targetOnlineState);

return Promise.resolve();
}

shutdown(): Promise<void> {
Expand Down