@@ -179,7 +179,7 @@ export class FirestoreClient {
179
179
user ,
180
180
persistenceResult
181
181
)
182
- . then ( ( ) => this . initializeRest ( user ) )
182
+ . then ( ( ) => this . initializeRest ( persistenceProvider , user ) )
183
183
. then ( initializationDone . resolve , initializationDone . reject ) ;
184
184
} else {
185
185
this . asyncQueue . enqueueAndForget ( ( ) => {
@@ -324,13 +324,20 @@ export class FirestoreClient {
324
324
* has been obtained from the credential provider and some persistence
325
325
* implementation is available in this.persistence.
326
326
*/
327
- private initializeRest ( user : User ) : Promise < void > {
327
+ private initializeRest (
328
+ persistenceProvider : PersistenceProvider ,
329
+ user : User
330
+ ) : Promise < void > {
328
331
logDebug ( LOG_TAG , 'Initializing. user=' , user . uid ) ;
329
332
return this . platform
330
333
. loadConnection ( this . databaseInfo )
331
334
. then ( async connection => {
332
335
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
+ ) ;
334
341
await this . localStore . start ( ) ;
335
342
const connectivityMonitor = this . platform . newConnectivityMonitor ( ) ;
336
343
const serializer = this . platform . newSerializer (
@@ -366,7 +373,7 @@ export class FirestoreClient {
366
373
connectivityMonitor
367
374
) ;
368
375
369
- this . syncEngine = new SyncEngine (
376
+ this . syncEngine = await persistenceProvider . newSyncEngine (
370
377
this . localStore ,
371
378
this . remoteStore ,
372
379
this . sharedClientState ,
@@ -378,25 +385,14 @@ export class FirestoreClient {
378
385
379
386
// Set up wiring between sync engine and other components
380
387
this . remoteStore . syncEngine = this . syncEngine ;
381
- this . sharedClientState . syncEngine = this . syncEngine ;
388
+ // this.sharedClientState.syncEngine = this.syncEngine;
382
389
383
390
this . eventMgr = new EventManager ( this . syncEngine ) ;
384
391
385
392
// PORTING NOTE: LocalStore doesn't need an explicit start() on the Web.
386
393
await this . sharedClientState . start ( ) ;
387
394
await this . remoteStore . start ( ) ;
388
395
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
-
400
396
// When a user calls clearPersistence() in one client, all other clients
401
397
// need to be terminated to allow the delete to succeed.
402
398
await this . persistence . setDatabaseDeletedListener ( async ( ) => {
0 commit comments