Skip to content

Commit fa87e58

Browse files
Clean up isPrimary
1 parent 3960fda commit fa87e58

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

packages/firestore/src/core/sync_engine.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,7 @@ export class SyncEngine implements RemoteSyncer {
918918
// PORTING NOTE: Web only
919919
export class MultiTabSyncEngine extends SyncEngine
920920
implements SharedClientStateSyncer {
921-
// The primary state is set to `true` or `false` immediately after Firestore
922-
// startup. In the interim, a client should only be considered primary if
923-
// `isPrimary` is true.
924-
private isPrimary: undefined | boolean = undefined;
921+
isPrimaryClient = false;
925922

926923
constructor(
927924
protected localStore: MultiTabLocalStore,
@@ -939,10 +936,6 @@ export class MultiTabSyncEngine extends SyncEngine
939936
);
940937
}
941938

942-
get isPrimaryClient(): boolean {
943-
return this.isPrimary === true;
944-
}
945-
946939
enableNetwork(): Promise<void> {
947940
this.localStore.setNetworkEnabled(true);
948941
return super.enableNetwork();
@@ -967,7 +960,7 @@ export class MultiTabSyncEngine extends SyncEngine
967960
const viewSnapshot = queryView.view.synchronizeWithPersistedState(
968961
queryResult
969962
);
970-
if (this.isPrimary) {
963+
if (this.isPrimaryClient) {
971964
this.updateTrackedLimbos(queryView.targetId, viewSnapshot.limboChanges);
972965
}
973966
return viewSnapshot;
@@ -1034,7 +1027,7 @@ export class MultiTabSyncEngine extends SyncEngine
10341027
}
10351028

10361029
async applyPrimaryState(isPrimary: boolean): Promise<void> {
1037-
if (isPrimary === true && this.isPrimary !== true) {
1030+
if (isPrimary === true && this.isPrimaryClient !== true) {
10381031
// Secondary tabs only maintain Views for their local listeners and the
10391032
// Views internal state may not be 100% populated (in particular
10401033
// secondary tabs don't track syncedDocuments, the set of documents the
@@ -1046,12 +1039,12 @@ export class MultiTabSyncEngine extends SyncEngine
10461039
activeTargets.toArray(),
10471040
/*transitionToPrimary=*/ true
10481041
);
1049-
this.isPrimary = true;
1042+
this.isPrimaryClient = true;
10501043
await this.remoteStore.applyPrimaryState(true);
10511044
for (const targetData of activeQueries) {
10521045
this.remoteStore.listen(targetData);
10531046
}
1054-
} else if (isPrimary === false && this.isPrimary !== false) {
1047+
} else if (isPrimary === false && this.isPrimaryClient !== false) {
10551048
const activeTargets: TargetId[] = [];
10561049

10571050
let p = Promise.resolve();
@@ -1076,7 +1069,7 @@ export class MultiTabSyncEngine extends SyncEngine
10761069
/*transitionToPrimary=*/ false
10771070
);
10781071
this.resetLimboDocuments();
1079-
this.isPrimary = false;
1072+
this.isPrimaryClient = false;
10801073
await this.remoteStore.applyPrimaryState(false);
10811074
}
10821075
}
@@ -1191,7 +1184,7 @@ export class MultiTabSyncEngine extends SyncEngine
11911184
state: QueryTargetState,
11921185
error?: FirestoreError
11931186
): Promise<void> {
1194-
if (this.isPrimary) {
1187+
if (this.isPrimaryClient) {
11951188
// If we receive a target state notification via WebStorage, we are
11961189
// either already secondary or another tab has taken the primary lease.
11971190
logDebug(LOG_TAG, 'Ignoring unexpected query state notification.');
@@ -1231,7 +1224,7 @@ export class MultiTabSyncEngine extends SyncEngine
12311224
added: TargetId[],
12321225
removed: TargetId[]
12331226
): Promise<void> {
1234-
if (!this.isPrimary) {
1227+
if (!this.isPrimaryClient) {
12351228
return;
12361229
}
12371230

0 commit comments

Comments
 (0)