Skip to content

Commit 8eaee68

Browse files
committed
Fixes from PR review
1 parent 9605531 commit 8eaee68

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

.changeset/small-geckos-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/firestore': patch
3+
---
4+
5+
Refactor Firestore client instantiation. This prepares for future features that require client to restart.

packages/firestore/src/core/firestore_client.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,9 @@ function readDocumentViaSnapshotListener(
656656
): Promise<void> {
657657
const wrappedObserver = new AsyncObserver({
658658
next: (snap: ViewSnapshot) => {
659-
// No further messages should be processed.
660-
wrappedObserver.mute();
661-
662-
// Remove query first before passing event to user to avoid
659+
// Mute and remove query first before passing event to user to avoid
663660
// user actions affecting the now stale query.
661+
wrappedObserver.mute();
664662
asyncQueue.enqueueAndForget(() =>
665663
eventManagerUnlisten(eventManager, listener)
666664
);
@@ -757,11 +755,9 @@ function executeQueryViaSnapshotListener(
757755
): Promise<void> {
758756
const wrappedObserver = new AsyncObserver<ViewSnapshot>({
759757
next: snapshot => {
760-
// No further messages should be processed.
761-
wrappedObserver.mute();
762-
763-
// Remove query first before passing event to user to avoid
758+
// Mute and remove query first before passing event to user to avoid
764759
// user actions affecting the now stale query.
760+
wrappedObserver.mute();
765761
asyncQueue.enqueueAndForget(() =>
766762
eventManagerUnlisten(eventManager, listener)
767763
);

packages/firestore/src/lite-api/database.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,18 @@ export class Firestore implements FirestoreService {
134134
}
135135

136136
_delete(): Promise<void> {
137+
// The `_terminateTask` must be assigned future that completes when
138+
// terminate is complete. The existence of this future puts SDK in state
139+
// that will not accept further API interaction.
137140
if (this._terminateTask === 'notTerminated') {
138141
this._terminateTask = this._terminate();
139142
}
140143
return this._terminateTask;
141144
}
142145

143146
async _restart(): Promise<void> {
147+
// The `_terminateTask` must equal 'notTerminated' after restart to
148+
// signal that client is in a state that accepts API calls.
144149
if (this._terminateTask === 'notTerminated') {
145150
await this._terminate();
146151
} else {

0 commit comments

Comments
 (0)