Skip to content

Commit a763d95

Browse files
Factor out Multi-Tab code
1 parent d69f79c commit a763d95

File tree

8 files changed

+287
-158
lines changed

8 files changed

+287
-158
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class FirestoreClient {
179179
user,
180180
persistenceResult
181181
)
182-
.then(() => this.initializeRest(user))
182+
.then(() => this.initializeRest(persistenceProvider, user))
183183
.then(initializationDone.resolve, initializationDone.reject);
184184
} else {
185185
this.asyncQueue.enqueueAndForget(() => {
@@ -324,13 +324,20 @@ export class FirestoreClient {
324324
* has been obtained from the credential provider and some persistence
325325
* implementation is available in this.persistence.
326326
*/
327-
private initializeRest(user: User): Promise<void> {
327+
private initializeRest(
328+
persistenceProvider: PersistenceProvider,
329+
user: User
330+
): Promise<void> {
328331
logDebug(LOG_TAG, 'Initializing. user=', user.uid);
329332
return this.platform
330333
.loadConnection(this.databaseInfo)
331334
.then(async connection => {
332335
const queryEngine = new IndexFreeQueryEngine();
333-
this.localStore = new LocalStore(this.persistence, queryEngine, user);
336+
this.localStore = persistenceProvider.newLocalStore(
337+
this.persistence,
338+
queryEngine,
339+
user
340+
);
334341
await this.localStore.start();
335342
const connectivityMonitor = this.platform.newConnectivityMonitor();
336343
const serializer = this.platform.newSerializer(
@@ -366,7 +373,7 @@ export class FirestoreClient {
366373
connectivityMonitor
367374
);
368375

369-
this.syncEngine = new SyncEngine(
376+
this.syncEngine = await persistenceProvider.newSyncEngine(
370377
this.localStore,
371378
this.remoteStore,
372379
this.sharedClientState,
@@ -378,25 +385,14 @@ export class FirestoreClient {
378385

379386
// Set up wiring between sync engine and other components
380387
this.remoteStore.syncEngine = this.syncEngine;
381-
this.sharedClientState.syncEngine = this.syncEngine;
388+
//this.sharedClientState.syncEngine = this.syncEngine;
382389

383390
this.eventMgr = new EventManager(this.syncEngine);
384391

385392
// PORTING NOTE: LocalStore doesn't need an explicit start() on the Web.
386393
await this.sharedClientState.start();
387394
await this.remoteStore.start();
388395

389-
// NOTE: This will immediately call the listener, so we make sure to
390-
// set it after localStore / remoteStore are started.
391-
await this.persistence.setPrimaryStateListener(async isPrimary => {
392-
await this.syncEngine.applyPrimaryState(isPrimary);
393-
if (isPrimary && !this.gcScheduler.started) {
394-
this.gcScheduler.start(this.localStore);
395-
} else if (!isPrimary) {
396-
this.gcScheduler.stop();
397-
}
398-
});
399-
400396
// When a user calls clearPersistence() in one client, all other clients
401397
// need to be terminated to allow the delete to succeed.
402398
await this.persistence.setDatabaseDeletedListener(async () => {

0 commit comments

Comments
 (0)