Skip to content

Commit bd1605c

Browse files
committed
feat: add start method for mutation and infinite-query
1 parent 1d73198 commit bd1605c

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

src/inifinite-query.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222

2323
import {
2424
InfiniteQueryConfig,
25-
InfiniteQueryDynamicOptions,
2625
InfiniteQueryInvalidateParams,
2726
InfiniteQueryOptions,
2827
InfiniteQueryResetParams,
29-
InfiniteQueryUpdateOptions,
28+
InfiniteQueryStartParams,
29+
InfiniteQueryUpdateOptionsAllVariants,
3030
} from './inifinite-query.types';
3131
import { AnyQueryClient, QueryClientHooks } from './query-client.types';
3232

@@ -203,14 +203,6 @@ export class InfiniteQuery<
203203
);
204204
}
205205

206-
private checkIsEnabled() {
207-
if (this.isEnabledOnResultDemand && !this.isResultRequsted) {
208-
return false;
209-
}
210-
211-
return this.holdedEnabledOption;
212-
}
213-
214206
fetchNextPage(options?: FetchNextPageOptions | undefined) {
215207
return this.queryObserver.fetchNextPage(options);
216208
}
@@ -220,10 +212,12 @@ export class InfiniteQuery<
220212
}
221213

222214
update(
223-
optionsUpdate:
224-
| Partial<InfiniteQueryOptions<TData, TError, TQueryKey, TPageParam>>
225-
| InfiniteQueryUpdateOptions<TData, TError, TQueryKey, TPageParam>
226-
| InfiniteQueryDynamicOptions<TData, TError, TQueryKey, TPageParam>,
215+
optionsUpdate: InfiniteQueryUpdateOptionsAllVariants<
216+
TData,
217+
TError,
218+
TQueryKey,
219+
TPageParam
220+
>,
227221
) {
228222
if (this.abortController.signal.aborted) {
229223
return;
@@ -365,6 +359,15 @@ export class InfiniteQuery<
365359
);
366360
}
367361

362+
async start({
363+
cancelRefetch,
364+
...params
365+
}: InfiniteQueryStartParams<TData, TError, TQueryKey, TPageParam> = {}) {
366+
this.update({ ...params });
367+
368+
return await this.refetch({ cancelRefetch });
369+
}
370+
368371
protected handleAbort = () => {
369372
this._observerSubscription?.();
370373

src/inifinite-query.types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
QueryKey,
55
InfiniteData,
66
DefaultedInfiniteQueryObserverOptions,
7+
RefetchOptions,
78
} from '@tanstack/query-core';
89

910
import { InfiniteQuery } from './inifinite-query';
@@ -96,6 +97,14 @@ export interface InfiniteQueryUpdateOptions<
9697
>
9798
> {}
9899

100+
export interface InfiniteQueryStartParams<
101+
TData,
102+
TError = DefaultError,
103+
TQueryKey extends QueryKey = QueryKey,
104+
TPageParam = unknown,
105+
> extends InfiniteQueryUpdateOptions<TData, TError, TQueryKey, TPageParam>,
106+
Pick<RefetchOptions, 'cancelRefetch'> {}
107+
99108
/**
100109
* @remarks ⚠️ use `InfiniteQueryUpdateOptions`. This type will be removed in next major release
101110
*/
@@ -118,6 +127,16 @@ export type InfiniteQueryConfigFromFn<
118127
TPageParam
119128
>;
120129

130+
export type InfiniteQueryUpdateOptionsAllVariants<
131+
TData,
132+
TError = DefaultError,
133+
TQueryKey extends QueryKey = any,
134+
TPageParam = unknown,
135+
> =
136+
| Partial<InfiniteQueryOptions<TData, TError, TQueryKey, TPageParam>>
137+
| InfiniteQueryUpdateOptions<TData, TError, TQueryKey, TPageParam>
138+
| InfiniteQueryDynamicOptions<TData, TError, TQueryKey, TPageParam>;
139+
121140
/**
122141
* @remarks ⚠️ use `InfiniteQueryConfigFromFn`. This type will be removed in next major release
123142
*/

src/mutation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ export class Mutation<
147147
return this.result;
148148
}
149149

150+
async start(
151+
variables: TVariables,
152+
options?: MutationOptions<TData, TError, TVariables, TContext>,
153+
) {
154+
await this.mutationObserver.mutate(variables, options);
155+
return this.result;
156+
}
157+
150158
/**
151159
* Modify this result so it matches the tanstack query result.
152160
*/

0 commit comments

Comments
 (0)