Skip to content

Commit 2610229

Browse files
WIP
1 parent ab8c6f5 commit 2610229

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class FirestoreClient {
176176

177177
this.platform
178178
.loadConnection(this.databaseInfo)
179-
.then(connection => {
179+
.then(async connection => {
180180
const connectivityMonitor = this.platform.newConnectivityMonitor();
181181
const serializer = this.platform.newSerializer(
182182
this.databaseInfo.databaseId
@@ -188,16 +188,23 @@ export class FirestoreClient {
188188
serializer
189189
);
190190

191-
return this.initializePersistence(
191+
await this.initializePersistence(
192192
datastore,
193193
connectivityMonitor,
194194
persistenceProvider,
195195
persistenceSettings,
196196
user,
197197
persistenceResult
198198
);
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+
});
199207
})
200-
.then(() => this.initializeRest(persistenceProvider))
201208
.then(initializationDone.resolve, initializationDone.reject);
202209
} else {
203210
this.asyncQueue.enqueueAndForget(() => {
@@ -268,6 +275,10 @@ export class FirestoreClient {
268275

269276
this.persistence = persistenceProvider.getPersistence();
270277
this.sharedClientState = persistenceProvider.getSharedClientState();
278+
this.localStore = persistenceProvider.getLocalStore();
279+
this.remoteStore = persistenceProvider.getRemoteStore();
280+
this.syncEngine = persistenceProvider.getSyncEngine();
281+
271282
persistenceResult.resolve();
272283
} catch (error) {
273284
// Regardless of whether or not the retry succeeds, from an user
@@ -343,30 +354,6 @@ export class FirestoreClient {
343354
}
344355
}
345356

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-
370357
private handleCredentialChange(user: User): Promise<void> {
371358
this.asyncQueue.verifyOperationInProgress();
372359

0 commit comments

Comments
 (0)