Skip to content

Commit 8cc3a21

Browse files
code cleanup
1 parent 39763bf commit 8cc3a21

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export abstract class AbstractQueryProcessor<
6868
this._closed = false;
6969
this.state = this.constructInitialState();
7070
this.disposeListeners = null;
71-
this.initialized = this.init();
71+
this.initialized = this.init(this.abortController.signal);
7272
}
7373

7474
protected constructInitialState(): WatchedQueryState<Data> {
@@ -113,7 +113,7 @@ export abstract class AbstractQueryProcessor<
113113
* Updates the underlying query.
114114
*/
115115
async updateSettings(settings: Settings) {
116-
// Abort any previous requests
116+
// Abort the previous request
117117
this.abortController.abort();
118118

119119
// Keep track of this controller's abort status
@@ -154,11 +154,8 @@ export abstract class AbstractQueryProcessor<
154154
/**
155155
* Configures base DB listeners and links the query to listeners.
156156
*/
157-
protected async init() {
157+
protected async init(signal: AbortSignal) {
158158
const { db } = this.options;
159-
// Make a ref copy of this early since it might be updated by updateSettings while this
160-
// method is running
161-
const { abortController } = this;
162159

163160
const disposeCloseListener = db.registerListener({
164161
closing: async () => {
@@ -183,7 +180,7 @@ export abstract class AbstractQueryProcessor<
183180

184181
// Initial setup
185182
await this.runWithReporting(async () => {
186-
await this.updateSettingsInternal(this.options.watchOptions, abortController.signal);
183+
await this.updateSettingsInternal(this.options.watchOptions, signal);
187184
});
188185
}
189186

packages/react/src/hooks/watched/useWatchedQuery.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ export const useWatchedQuery = <RowType = unknown>(
3939

4040
React.useEffect(() => {
4141
watchedQuery?.close();
42-
setWatchedQuery(createWatchedQuery);
42+
const newQuery = createWatchedQuery();
43+
setWatchedQuery(newQuery);
4344

4445
return () => {
4546
disposePendingUpdateListener.current?.();
46-
watchedQuery?.close();
47+
newQuery?.close();
4748
};
4849
}, [powerSync, active]);
4950

0 commit comments

Comments
 (0)