Skip to content

Commit b04f425

Browse files
Try downlevelIteration
1 parent bccccb5 commit b04f425

File tree

6 files changed

+29
-31
lines changed

6 files changed

+29
-31
lines changed

packages/firestore/src/core/sync_engine.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
398398
try {
399399
const changes = await this.localStore.applyRemoteEvent(remoteEvent);
400400
// Update `receivedDocument` as appropriate for any limbo targets.
401-
remoteEvent.targetChanges.forEach((targetChange, targetId) => {
401+
for (const [targetId, targetChange] of remoteEvent.targetChanges) {
402402
const limboResolution = this.limboResolutionsByTarget.get(targetId);
403403
if (limboResolution) {
404404
// Since this is a limbo resolution lookup, it's for a single document
@@ -427,7 +427,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
427427
// This was probably just a CURRENT targetChange or similar.
428428
}
429429
}
430-
});
430+
}
431431
await this.emitNewSnapsAndNotifyLocalStore(changes, remoteEvent);
432432
} catch (error) {
433433
await ignoreIfPrimaryLeaseLoss(error);
@@ -643,11 +643,11 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
643643

644644
/** Reject all outstanding callbacks waiting for pending writes to complete. */
645645
private rejectOutstandingPendingWritesCallbacks(errorMessage: string): void {
646-
this.pendingWritesCallbacks.forEach(callbacks => {
647-
callbacks.forEach(callback => {
646+
for (const [_, callbacks] of this.pendingWritesCallbacks) {
647+
for (const callback of callbacks) {
648648
callback.reject(new FirestoreError(Code.CANCELLED, errorMessage));
649-
});
650-
});
649+
}
650+
}
651651

652652
this.pendingWritesCallbacks.clear();
653653
}
@@ -913,22 +913,18 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
913913

914914
const activeTargets: TargetId[] = [];
915915

916-
let p = Promise.resolve();
917-
this.queriesByTarget.forEach((_, targetId) => {
916+
for (const [targetId] of this.queriesByTarget) {
918917
if (this.sharedClientState.isLocalQueryTarget(targetId)) {
919918
activeTargets.push(targetId);
920919
} else {
921-
p = p.then(() => {
922-
this.removeAndCleanupTarget(targetId);
923-
return this.localStore.releaseTarget(
924-
targetId,
925-
/*keepPersistedTargetData=*/ true
926-
);
927-
});
920+
await this.removeAndCleanupTarget(targetId);
921+
await this.localStore.releaseTarget(
922+
targetId,
923+
/*keepPersistedTargetData=*/ true
924+
);
928925
}
929926
this.remoteStore.unlisten(targetId);
930-
});
931-
await p;
927+
}
932928

933929
await this.synchronizeQueryViewsAndRaiseSnapshots(activeTargets);
934930
this.resetLimboDocuments();
@@ -938,9 +934,9 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
938934

939935
// PORTING NOTE: Multi-tab only.
940936
private resetLimboDocuments(): void {
941-
this.limboResolutionsByTarget.forEach((_, targetId) => {
937+
for (const [targetId] of this.limboResolutionsByTarget) {
942938
this.remoteStore.unlisten(targetId);
943-
});
939+
}
944940
this.limboDocumentRefs.removeAllReferences();
945941
this.limboResolutionsByTarget = new Map<TargetId, LimboResolution>();
946942
this.limboTargetsByKey = new SortedMap<DocumentKey, TargetId>(

packages/firestore/src/local/local_store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ export class LocalStore {
519519
newTargetDataByTargetMap = this.targetDataByTarget;
520520

521521
const promises = [] as Array<PersistencePromise<void>>;
522-
remoteEvent.targetChanges.forEach((change, targetId) => {
522+
for (const [targetId, change] of remoteEvent.targetChanges) {
523523
const oldTargetData = newTargetDataByTargetMap.get(targetId);
524524
if (!oldTargetData) {
525-
return;
525+
continue;
526526
}
527527

528528
// Only update the remote keys if the target is still active. This
@@ -565,7 +565,7 @@ export class LocalStore {
565565
);
566566
}
567567
}
568-
});
568+
}
569569

570570
let changedDocs = maybeDocumentMap();
571571
let updatedKeys = documentKeySet();

packages/firestore/src/model/field_value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class ObjectValueBuilder {
256256
{ ...existingValue.mapValue.fields }
257257
: {};
258258

259-
currentOverlays.forEach((value, pathSegment) => {
259+
for (const [pathSegment, value] of currentOverlays) {
260260
if (value instanceof Map) {
261261
const nested = this.applyOverlay(currentPath.child(pathSegment), value);
262262
if (nested != null) {
@@ -270,7 +270,7 @@ export class ObjectValueBuilder {
270270
delete resultAtPath[pathSegment];
271271
modified = true;
272272
}
273-
});
273+
}
274274

275275
return modified ? { mapValue: { fields: resultAtPath } } : null;
276276
}

packages/firestore/src/remote/remote_store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ export class RemoteStore implements TargetMetadataProvider {
343343
}
344344

345345
private async onWatchStreamOpen(): Promise<void> {
346-
this.listenTargets.forEach((targetData, targetId) => {
346+
for (const [_, targetData] of this.listenTargets) {
347347
this.sendWatchRequest(targetData);
348-
});
348+
}
349349
}
350350

351351
private async onWatchStreamClose(error?: FirestoreError): Promise<void> {
@@ -428,7 +428,7 @@ export class RemoteStore implements TargetMetadataProvider {
428428

429429
// Update in-memory resume tokens. LocalStore will update the
430430
// persistent view of these when applying the completed RemoteEvent.
431-
remoteEvent.targetChanges.forEach((change, targetId) => {
431+
for (const [targetId, change] of remoteEvent.targetChanges) {
432432
if (change.resumeToken.approximateByteSize() > 0) {
433433
const targetData = this.listenTargets.get(targetId);
434434
// A watched target might have been removed already.
@@ -439,7 +439,7 @@ export class RemoteStore implements TargetMetadataProvider {
439439
);
440440
}
441441
}
442-
});
442+
}
443443

444444
// Re-establish listens for the targets that have been invalidated by
445445
// existence filter mismatches.

packages/firestore/src/remote/watch_change.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export class WatchChangeAggregator {
422422
createRemoteEvent(snapshotVersion: SnapshotVersion): RemoteEvent {
423423
const targetChanges = new Map<TargetId, TargetChange>();
424424

425-
this.targetStates.forEach((targetState, targetId) => {
425+
for (const [targetId, targetState] of this.targetStates) {
426426
const targetData = this.targetDataForActiveTarget(targetId);
427427
if (targetData) {
428428
if (targetState.current && targetData.target.isDocumentQuery()) {
@@ -453,7 +453,7 @@ export class WatchChangeAggregator {
453453
targetState.clearPendingChanges();
454454
}
455455
}
456-
});
456+
}
457457

458458
let resolvedLimboDocuments = documentKeySet();
459459

packages/firestore/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "dist",
5+
"downlevelIteration": true,
6+
"importHelpers": true
57
},
68
"exclude": [
79
"dist/**/*"

0 commit comments

Comments
 (0)