Skip to content

Firestore: settings.ts: very minor refactor of long-polling logic. #7239

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 10 commits into from
Apr 21, 2023
23 changes: 18 additions & 5 deletions packages/firestore/src/lite-api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { validateIsNotUsedTogether } from '../util/input_validation';
export const DEFAULT_HOST = 'firestore.googleapis.com';
export const DEFAULT_SSL = true;

const DEFAULT_AUTO_DETECT_LONG_POLLING = false;

/**
* Specifies custom configurations for your Cloud Firestore instance.
* You must set these before invoking any other methods.
Expand Down Expand Up @@ -123,17 +125,28 @@ export class FirestoreSettingsImpl {
}
}

this.experimentalForceLongPolling = !!settings.experimentalForceLongPolling;
this.experimentalAutoDetectLongPolling =
!!settings.experimentalAutoDetectLongPolling;
this.useFetchStreams = !!settings.useFetchStreams;

validateIsNotUsedTogether(
'experimentalForceLongPolling',
settings.experimentalForceLongPolling,
'experimentalAutoDetectLongPolling',
settings.experimentalAutoDetectLongPolling
);

this.experimentalForceLongPolling = !!settings.experimentalForceLongPolling;

if (this.experimentalForceLongPolling) {
this.experimentalAutoDetectLongPolling = false;
} else if (settings.experimentalAutoDetectLongPolling === undefined) {
this.experimentalAutoDetectLongPolling = DEFAULT_AUTO_DETECT_LONG_POLLING;
} else {
// For backwards compatibility, coerce the value to boolean even though
// the TypeScript compiler has narrowed the type to boolean already.
// noinspection PointlessBooleanExpressionJS
this.experimentalAutoDetectLongPolling =
!!settings.experimentalAutoDetectLongPolling;
}

this.useFetchStreams = !!settings.useFetchStreams;
}

isEqual(other: FirestoreSettingsImpl): boolean {
Expand Down