Skip to content

Commit ab2d7d9

Browse files
committed
feat: add Disposable methods for tanstack query entities (for 'using' keyword)
1 parent 80d38e4 commit ab2d7d9

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/mobx-inifinite-query.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export class MobxInfiniteQuery<
3636
TError = DefaultError,
3737
TQueryKey extends QueryKey = any,
3838
TPageParam = unknown,
39-
> {
39+
> implements Disposable
40+
{
4041
protected abortController: AbortController;
4142
protected queryClient: QueryClient | MobxQueryClient;
4243

@@ -348,4 +349,8 @@ export class MobxInfiniteQuery<
348349
dispose() {
349350
this.destroy();
350351
}
352+
353+
[Symbol.dispose](): void {
354+
this.destroy();
355+
}
351356
}

src/mobx-mutation.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class MobxMutation<
1717
TVariables = void,
1818
TError = DefaultError,
1919
TContext = unknown,
20-
> {
20+
> implements Disposable
21+
{
2122
protected abortController: AbortController;
2223
protected queryClient: QueryClient | MobxQueryClient;
2324

@@ -143,7 +144,18 @@ export class MobxMutation<
143144
delete this._observerSubscription;
144145
};
145146

146-
dispose() {
147+
destroy() {
147148
this.abortController.abort();
148149
}
150+
151+
/**
152+
* @deprecated use `destroy`
153+
*/
154+
dispose() {
155+
this.destroy();
156+
}
157+
158+
[Symbol.dispose](): void {
159+
this.destroy();
160+
}
149161
}

src/mobx-query.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class MobxQuery<
3232
TData,
3333
TError = DefaultError,
3434
TQueryKey extends QueryKey = any,
35-
> {
35+
> implements Disposable
36+
{
3637
protected abortController: AbortController;
3738
protected queryClient: QueryClient | MobxQueryClient;
3839

@@ -308,4 +309,8 @@ export class MobxQuery<
308309
dispose() {
309310
this.destroy();
310311
}
312+
313+
[Symbol.dispose](): void {
314+
this.destroy();
315+
}
311316
}

0 commit comments

Comments
 (0)