Skip to content

Commit 5296fa7

Browse files
committed
Minimum implementation to handle global resume tokens
1 parent 8154c4b commit 5296fa7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/firestore/src/remote/watch_change.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class WatchChangeAggregator {
297297

298298
/** Processes and adds the WatchTargetChange to the current set of changes. */
299299
handleTargetChange(targetChange: WatchTargetChange): void {
300-
targetChange.targetIds.forEach(targetId => {
300+
this.forEachTargetId(targetChange, targetId => {
301301
const targetState = this.ensureTargetState(targetId);
302302
switch (targetChange.state) {
303303
case WatchTargetChangeState.NoChange:
@@ -352,6 +352,24 @@ export class WatchChangeAggregator {
352352
});
353353
}
354354

355+
/**
356+
* Iterates over all targetIds that the watch change applies to: either the
357+
* targetIds explicitly listed in the change or the targetIds of all currently
358+
* active targets.
359+
*/
360+
forEachTargetId(
361+
targetChange: WatchTargetChange,
362+
fn: (targetId: TargetId) => void
363+
): void {
364+
if (targetChange.targetIds.length > 0) {
365+
targetChange.targetIds.forEach(fn);
366+
} else {
367+
objUtils.forEachNumber(this.targetStates, (targetId, _) => {
368+
fn(targetId);
369+
});
370+
}
371+
}
372+
355373
/**
356374
* Handles existence filters and synthesizes deletes for filter mismatches.
357375
* Targets that are invalidated by filter mismatches are added to

0 commit comments

Comments
 (0)