@@ -176,7 +176,7 @@ export class FirestoreClient {
176
176
177
177
this . platform
178
178
. loadConnection ( this . databaseInfo )
179
- . then ( connection => {
179
+ . then ( async connection => {
180
180
const connectivityMonitor = this . platform . newConnectivityMonitor ( ) ;
181
181
const serializer = this . platform . newSerializer (
182
182
this . databaseInfo . databaseId
@@ -188,16 +188,23 @@ export class FirestoreClient {
188
188
serializer
189
189
) ;
190
190
191
- return this . initializePersistence (
191
+ await this . initializePersistence (
192
192
datastore ,
193
193
connectivityMonitor ,
194
194
persistenceProvider ,
195
195
persistenceSettings ,
196
196
user ,
197
197
persistenceResult
198
198
) ;
199
+
200
+ this . eventMgr = new EventManager ( this . syncEngine ) ;
201
+
202
+ // When a user calls clearPersistence() in one client, all other clients
203
+ // need to be terminated to allow the delete to succeed.
204
+ this . persistence . setDatabaseDeletedListener ( async ( ) => {
205
+ await this . terminate ( ) ;
206
+ } ) ;
199
207
} )
200
- . then ( ( ) => this . initializeRest ( persistenceProvider ) )
201
208
. then ( initializationDone . resolve , initializationDone . reject ) ;
202
209
} else {
203
210
this . asyncQueue . enqueueAndForget ( ( ) => {
@@ -268,6 +275,10 @@ export class FirestoreClient {
268
275
269
276
this . persistence = persistenceProvider . getPersistence ( ) ;
270
277
this . sharedClientState = persistenceProvider . getSharedClientState ( ) ;
278
+ this . localStore = persistenceProvider . getLocalStore ( ) ;
279
+ this . remoteStore = persistenceProvider . getRemoteStore ( ) ;
280
+ this . syncEngine = persistenceProvider . getSyncEngine ( ) ;
281
+
271
282
persistenceResult . resolve ( ) ;
272
283
} catch ( error ) {
273
284
// Regardless of whether or not the retry succeeds, from an user
@@ -343,30 +354,6 @@ export class FirestoreClient {
343
354
}
344
355
}
345
356
346
- /**
347
- * Initializes the rest of the FirestoreClient, assuming the initial user
348
- * has been obtained from the credential provider and some persistence
349
- * implementation is available in this.persistence.
350
- */
351
- private initializeRest (
352
- persistenceProvider : PersistenceProvider
353
- ) : Promise < void > {
354
- return this . platform
355
- . loadConnection ( this . databaseInfo )
356
- . then ( async connection => {
357
- this . localStore = persistenceProvider . getLocalStore ( ) ;
358
- this . remoteStore = persistenceProvider . getRemoteStore ( ) ;
359
- this . syncEngine = persistenceProvider . getSyncEngine ( ) ;
360
- this . eventMgr = new EventManager ( this . syncEngine ) ;
361
-
362
- // When a user calls clearPersistence() in one client, all other clients
363
- // need to be terminated to allow the delete to succeed.
364
- await this . persistence . setDatabaseDeletedListener ( async ( ) => {
365
- await this . terminate ( ) ;
366
- } ) ;
367
- } ) ;
368
- }
369
-
370
357
private handleCredentialChange ( user : User ) : Promise < void > {
371
358
this . asyncQueue . verifyOperationInProgress ( ) ;
372
359
0 commit comments