Skip to content

Commit 69e746c

Browse files
Remove duplication
1 parent cab645d commit 69e746c

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ export class FirestoreClient {
209209
/** Enables the network connection and requeues all pending operations. */
210210
enableNetwork(): Promise<void> {
211211
this.verifyNotTerminated();
212-
return enqueueEnableNetwork(
212+
return enqueueNetworkEnabled(
213213
this.asyncQueue,
214214
this.remoteStore,
215-
this.persistence
215+
this.persistence,
216+
/* enabled= */ true
216217
);
217218
}
218219

@@ -353,10 +354,11 @@ export class FirestoreClient {
353354
/** Disables the network connection. Pending operations will not complete. */
354355
disableNetwork(): Promise<void> {
355356
this.verifyNotTerminated();
356-
return enqueueDisableNetwork(
357+
return enqueueNetworkEnabled(
357358
this.asyncQueue,
358359
this.remoteStore,
359-
this.persistence
360+
this.persistence,
361+
/* enabled= */ false
360362
);
361363
}
362364

@@ -461,35 +463,18 @@ export function enqueueWrite(
461463
return deferred.promise;
462464
}
463465

464-
/** Enables the network connection and requeues all pending operations. */
465-
export function enqueueEnableNetwork(
466+
export function enqueueNetworkEnabled(
466467
asyncQueue: AsyncQueue,
467468
remoteStore: RemoteStore,
468-
persistence: Persistence
469+
persistence: Persistence,
470+
enabled: boolean
469471
): Promise<void> {
470472
return asyncQueue.enqueue(() => {
471473
persistence.setNetworkEnabled(true);
472-
return remoteStore.enableNetwork();
474+
return enabled ? remoteStore.enableNetwork() : remoteStore.disableNetwork();
473475
});
474476
}
475477

476-
/** Disables the network connection. Pending operations will not complete. */
477-
export function enqueueDisableNetwork(
478-
asyncQueue: AsyncQueue,
479-
remoteStore: RemoteStore,
480-
persistence: Persistence
481-
): Promise<void> {
482-
return asyncQueue.enqueue(() => {
483-
persistence.setNetworkEnabled(false);
484-
return remoteStore.disableNetwork();
485-
});
486-
}
487-
488-
/**
489-
* Returns a Promise that resolves when all writes that were pending at the time this
490-
* method was called received server acknowledgement. An acknowledgement can be either acceptance
491-
* or rejection.
492-
*/
493478
export function enqueueWaitForPendingWrites(
494479
asyncQueue: AsyncQueue,
495480
syncEngine: SyncEngine
@@ -517,7 +502,6 @@ export function enqueueListen(
517502
};
518503
}
519504

520-
/** Registers the listener for onSnapshotsInSync() */
521505
export function enqueueSnapshotsInSyncListen(
522506
asyncQueue: AsyncQueue,
523507
eventManager: EventManager,

0 commit comments

Comments
 (0)