Skip to content

Clean up isPrimary #3058

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 1 commit into from
May 13, 2020
Merged
Changes from all 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
18 changes: 9 additions & 9 deletions packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ export class MultiTabSyncEngine extends SyncEngine
// The primary state is set to `true` or `false` immediately after Firestore
// startup. In the interim, a client should only be considered primary if
// `isPrimary` is true.
private isPrimary: undefined | boolean = undefined;
private _isPrimaryClient: undefined | boolean = undefined;

constructor(
protected localStore: MultiTabLocalStore,
Expand All @@ -940,7 +940,7 @@ export class MultiTabSyncEngine extends SyncEngine
}

get isPrimaryClient(): boolean {
return this.isPrimary === true;
return this._isPrimaryClient === true;
}

enableNetwork(): Promise<void> {
Expand All @@ -967,7 +967,7 @@ export class MultiTabSyncEngine extends SyncEngine
const viewSnapshot = queryView.view.synchronizeWithPersistedState(
queryResult
);
if (this.isPrimary) {
if (this._isPrimaryClient) {
this.updateTrackedLimbos(queryView.targetId, viewSnapshot.limboChanges);
}
return viewSnapshot;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ export class MultiTabSyncEngine extends SyncEngine
}

async applyPrimaryState(isPrimary: boolean): Promise<void> {
if (isPrimary === true && this.isPrimary !== true) {
if (isPrimary === true && this._isPrimaryClient !== true) {
// Secondary tabs only maintain Views for their local listeners and the
// Views internal state may not be 100% populated (in particular
// secondary tabs don't track syncedDocuments, the set of documents the
Expand All @@ -1046,12 +1046,12 @@ export class MultiTabSyncEngine extends SyncEngine
activeTargets.toArray(),
/*transitionToPrimary=*/ true
);
this.isPrimary = true;
this._isPrimaryClient = true;
await this.remoteStore.applyPrimaryState(true);
for (const targetData of activeQueries) {
this.remoteStore.listen(targetData);
}
} else if (isPrimary === false && this.isPrimary !== false) {
} else if (isPrimary === false && this._isPrimaryClient !== false) {
const activeTargets: TargetId[] = [];

let p = Promise.resolve();
Expand All @@ -1076,7 +1076,7 @@ export class MultiTabSyncEngine extends SyncEngine
/*transitionToPrimary=*/ false
);
this.resetLimboDocuments();
this.isPrimary = false;
this._isPrimaryClient = false;
await this.remoteStore.applyPrimaryState(false);
}
}
Expand Down Expand Up @@ -1191,7 +1191,7 @@ export class MultiTabSyncEngine extends SyncEngine
state: QueryTargetState,
error?: FirestoreError
): Promise<void> {
if (this.isPrimary) {
if (this._isPrimaryClient) {
// If we receive a target state notification via WebStorage, we are
// either already secondary or another tab has taken the primary lease.
logDebug(LOG_TAG, 'Ignoring unexpected query state notification.');
Expand Down Expand Up @@ -1231,7 +1231,7 @@ export class MultiTabSyncEngine extends SyncEngine
added: TargetId[],
removed: TargetId[]
): Promise<void> {
if (!this.isPrimary) {
if (!this._isPrimaryClient) {
return;
}

Expand Down