Skip to content

Commit 4ee5d2c

Browse files
Improve updateSettings even further
1 parent 0c5f167 commit 4ee5d2c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/common/src/client/watched/processors/AbstractQueryProcessor.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,22 @@ export abstract class AbstractQueryProcessor<
7979
return this.options.watchOptions.reportFetching ?? true;
8080
}
8181

82-
/**
83-
* Updates the underlying query.
84-
*/
85-
async updateSettings(settings: Settings) {
82+
protected async updateSettingsInternal(settings: Settings) {
8683
// Abort any previous requests
8784
this.abortController.abort();
8885

89-
this.options.watchOptions = settings;
9086
// Keep track of this controller's abort status
9187
const abortController = new AbortController();
9288
// Allow this to be aborted externally
9389
this.abortController = abortController;
9490

95-
await this.initialized;
96-
9791
// This may have been aborted while awaiting or if multiple calls to `updateSettings` were made
9892
if (abortController.signal.aborted) {
9993
return;
10094
}
10195

96+
this.options.watchOptions = settings;
97+
10298
if (!this.state.isFetching && this.reportFetching) {
10399
await this.updateState({
104100
isFetching: true
@@ -113,6 +109,14 @@ export abstract class AbstractQueryProcessor<
113109
);
114110
}
115111

112+
/**
113+
* Updates the underlying query.
114+
*/
115+
async updateSettings(settings: Settings) {
116+
await this.initialized;
117+
return this.updateSettingsInternal(settings);
118+
}
119+
116120
/**
117121
* This method is used to link a query to the subscribers of this listener class.
118122
* This method should perform actual query watching and report results via {@link updateState} method.
@@ -163,8 +167,8 @@ export abstract class AbstractQueryProcessor<
163167
};
164168

165169
// Initial setup
166-
this.runWithReporting(async () => {
167-
await this.updateSettings(this.options.watchOptions);
170+
await this.runWithReporting(async () => {
171+
await this.updateSettingsInternal(this.options.watchOptions);
168172
});
169173
}
170174

packages/web/tests/watch.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,12 +766,14 @@ describe('Watch Tests', { sequential: true }, () => {
766766

767767
await vi.waitFor(
768768
() => {
769+
console.log(JSON.stringify(states));
769770
expect(states[states.length - 1].isFetching).false;
770771
expect(states[states.length - 1].data[0].result).eq(100);
771772
},
772773
{ timeout: 3000 }
773774
);
774775
dispose();
776+
console.log(JSON.stringify(states));
775777
});
776778

777779
it('should report differential query results', async () => {

0 commit comments

Comments
 (0)