Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/huge-ties-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"mobx-tanstack-query": major
---

### Breaking changes

- Removed deprecated `Destroyable.dispose()` — use `destroy()` or `Symbol.dispose` / `using` where supported.
- Removed `Mobx*` type aliases and `MobxQuery` / `MobxMutation` / `MobxInfiniteQuery` class aliases; import the canonical names (`Query`, `Mutation`, `InfiniteQuery`, `QueryOptions`, `DefaultOptions`, etc.).
- Removed deprecated query client aliases: `IQueryClient`, `QueryClientInterface`, `MobxDefaultOptions`, `MobxQueryClientHooks`, `MobxQueryClientConfig`.
- Removed `resetOnDispose` from query features and mutation options / defaults — use `resetOnDestroy` only.
6 changes: 1 addition & 5 deletions src/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ export abstract class BaseQuery<
config.cumulativeQueryHash ?? qf?.cumulativeQueryHash,
enableOnDemand: config.enableOnDemand ?? qf?.enableOnDemand,
lazy: config.lazy ?? qf?.lazy,
resetOnDestroy:
config.resetOnDestroy ??
config.resetOnDispose ??
qf?.resetOnDestroy ??
qf?.resetOnDispose,
resetOnDestroy: config.resetOnDestroy ?? qf?.resetOnDestroy,
removeOnDestroy: config.removeOnDestroy ?? qf?.removeOnDestroy,
transformError: config.transformError ?? qf?.transformError,
dynamicOptionsUpdateDelay:
Expand Down
22 changes: 11 additions & 11 deletions src/infinite-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InfiniteQueryMock<
queryFn: null as unknown as ReturnType<typeof vi.fn>,
setData: vi.fn(),
update: vi.fn(),
dispose: vi.fn(),
destroy: vi.fn(),
refetch: vi.fn(),
invalidate: vi.fn(),
onDone: vi.fn(),
Expand Down Expand Up @@ -107,9 +107,9 @@ class InfiniteQueryMock<
return result;
}

dispose(): void {
const result = super.dispose();
this.spies.dispose.mockReturnValue(result)();
destroy(): void {
const result = super.destroy();
this.spies.destroy.mockReturnValue(result)();
}
}

Expand All @@ -130,7 +130,7 @@ describe('InfiniteQuery', () => {
queryKey: ['test'],
});

query.dispose();
query.destroy();
});

it('should call queryFn with initialPageParam', async () => {
Expand All @@ -150,7 +150,7 @@ describe('InfiniteQuery', () => {
queryKey: ['test'],
});

query.dispose();
query.destroy();
});

it('should use initialPageParam from dynamic options without top-level initialPageParam', async () => {
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('InfiniteQuery', () => {
queryKey: ['test'],
});

query.dispose();
query.destroy();
});

it('should call queryFn with getNextPageParam returning null', async () => {
Expand Down Expand Up @@ -352,7 +352,7 @@ describe('InfiniteQuery', () => {
status: 'success',
});

query.dispose();
query.destroy();
});

it('should call queryFn after fetchNextPage call', async () => {
Expand Down Expand Up @@ -438,7 +438,7 @@ describe('InfiniteQuery', () => {
status: 'success',
});

query.dispose();
query.destroy();
});

it('should call queryFn after fetchNextPage call (x3 times)', async () => {
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('InfiniteQuery', () => {
status: 'success',
});

query.dispose();
query.destroy();
});

describe('"enabled" reactive parameter', () => {
Expand All @@ -556,7 +556,7 @@ describe('InfiniteQuery', () => {
expect(query.spies.queryFn).toBeCalledTimes(1);
expect(query.spies.queryFn).nthReturnedWith(1, 100);

query.dispose();
query.destroy();
});
});

Expand Down
16 changes: 0 additions & 16 deletions src/inifinite-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,3 @@ export class InfiniteQuery<
this.hooks?.onInfiniteQueryDestroy?.(this);
}
}

/**
* @deprecated ⚠️ use `InfiniteQuery`. This export will be removed in next major release
*/
export class MobxInfiniteQuery<
TData,
TError = DefaultError,
TQueryKey extends QueryKey = any,
TPageParam = unknown,
> extends InfiniteQuery<
TData,
TError,
TPageParam,
InfiniteData<TData, TPageParam>,
TQueryKey
> {}
84 changes: 0 additions & 84 deletions src/inifinite-query.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,9 @@ export type InfiniteQueryDoneListener<TData = unknown> = (

export interface InfiniteQueryInvalidateParams extends QueryInvalidateParams {}

/**
* @deprecated ⚠️ use `InfiniteQueryInvalidateParams`. This type will be removed in next major release
*/
export type MobxInfiniteQueryInvalidateParams = InfiniteQueryInvalidateParams;

export interface InfiniteQueryResetParams extends QueryResetParams {}
export interface InfiniteQueryRemoveParams extends QueryRemoveParams {}

/**
* @deprecated ⚠️ use `InfiniteQueryResetParams`. This type will be removed in next major release
*/
export type MobxInfiniteQueryResetParams = InfiniteQueryResetParams;

type InfiniteQueryOptionTypeFixes<
TQueryFnData = unknown,
TError = DefaultError,
Expand Down Expand Up @@ -86,22 +76,6 @@ export interface InfiniteQueryDynamicOptions<
enabled?: boolean;
}

/**
* @deprecated ⚠️ use `InfiniteQueryDynamicOptions`. This type will be removed in next major release
*/
export type MobxInfiniteQueryDynamicOptions<
TData,
TError = DefaultError,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
> = InfiniteQueryDynamicOptions<
TData,
TError,
TPageParam,
InfiniteData<TData, TPageParam>,
TQueryKey
>;

export interface InfiniteQueryOptions<
TQueryFnData = unknown,
TError = DefaultError,
Expand All @@ -126,22 +100,6 @@ export interface InfiniteQueryOptions<
TQueryKey
> {}

/**
* @deprecated ⚠️ use `InfiniteQueryOptions`. This type will be removed in next major release
*/
export type MobxInfiniteQueryOptions<
TData,
TError = DefaultError,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
> = InfiniteQueryOptions<
TData,
TError,
TPageParam,
InfiniteData<TData, TPageParam>,
TQueryKey
>;

export interface InfiniteQueryUpdateOptions<
TQueryFnData = unknown,
TError = DefaultError,
Expand Down Expand Up @@ -183,22 +141,6 @@ export interface InfiniteQueryStartParams<
>,
Pick<RefetchOptions, 'cancelRefetch'> {}

/**
* @deprecated ⚠️ use `InfiniteQueryUpdateOptions`. This type will be removed in next major release
*/
export type MobxInfiniteQueryUpdateOptions<
TData,
TError = DefaultError,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
> = InfiniteQueryUpdateOptions<
TData,
TError,
TPageParam,
InfiniteData<TData, TPageParam>,
TQueryKey
>;

export type InfiniteQueryConfigFromFn<
TFn extends (...args: any[]) => any,
TError = DefaultError,
Expand Down Expand Up @@ -240,16 +182,6 @@ export type InfiniteQueryUpdateOptionsAllVariants<
TQueryKey
>;

/**
* @deprecated ⚠️ use `InfiniteQueryConfigFromFn`. This type will be removed in next major release
*/
export type MobxInfiniteQueryConfigFromFn<
TFn extends (...args: any[]) => any,
TError = DefaultError,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
> = InfiniteQueryConfigFromFn<TFn, TError, TQueryKey, TPageParam>;

export interface InfiniteQueryConfig<
TQueryFnData = unknown,
TError = DefaultError,
Expand Down Expand Up @@ -332,22 +264,6 @@ export interface InfiniteQueryFlattenConfig<
queryKey?: TQueryKey;
}

/**
* @deprecated ⚠️ use `InfiniteQueryConfig`. This type will be removed in next major release
*/
export type MobxInfiniteQueryConfig<
TData,
TError = DefaultError,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
> = InfiniteQueryConfig<
TData,
TError,
TPageParam,
InfiniteData<TData, TPageParam>,
TQueryKey
>;

export type InferInfiniteQuery<
T extends
| InfiniteQueryConfig<any, any, any, any, any>
Expand Down
99 changes: 95 additions & 4 deletions src/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
MutationFn,
MutationFunctionContext,
} from './mutation.types.js';
import { QueryClient as MobxQueryClient } from './query-client.js';

class MutationMock<
TData = unknown,
Expand All @@ -20,7 +21,7 @@ class MutationMock<
> extends Mutation<TData, TVariables, TError, TContext> {
spies = {
mutationFn: null as unknown as ReturnType<typeof vi.fn>,
dispose: vi.fn(),
destroy: vi.fn(),
reset: vi.fn(),
onDone: vi.fn(),
onError: vi.fn(),
Expand Down Expand Up @@ -54,9 +55,9 @@ class MutationMock<
this.spies.reset.mockReturnValue(result)();
}

dispose(): void {
const result = super.dispose();
this.spies.dispose.mockReturnValue(result)();
destroy(): void {
const result = super.destroy();
this.spies.destroy.mockReturnValue(result)();
}
}

Expand Down Expand Up @@ -219,4 +220,94 @@ describe('Mutation', () => {
Mutation<void, void, Error, unknown>
>();
});

describe('resetOnDestroy vs deprecated resetOnDispose (Mutation constructor features)', () => {
/**
* Targets `resetOnDestroy: config.resetOnDestroy ?? qc.mutationFeatures?.resetOnDestroy`.
* `qc.mutationFeatures.resetOnDispose` must not enable reset-on-destroy.
*/
it('does not use qc.mutationFeatures.resetOnDispose when config.resetOnDestroy is undefined', async () => {
const queryClient = new MobxQueryClient({
defaultOptions: {
// Legacy runtime key; must not map to reset-on-destroy (see Mutation constructor).
mutations: {
resetOnDispose: true,
} as MobxQueryClient['mutationFeatures'],
},
});

const mutation = new Mutation({
queryClient,
mutationKey: ['reset-regression'],
mutationFn: async () => 'ok',
});

await mutation.mutate();
expect(mutation.result.status).toBe('success');
mutation.destroy();
expect(mutation.result.status).toBe('success');
});

it('honors qc.mutationFeatures.resetOnDestroy when config.resetOnDestroy is undefined', async () => {
const queryClient = new MobxQueryClient({
defaultOptions: {
mutations: { resetOnDestroy: true },
},
});

const mutation = new Mutation({
queryClient,
mutationKey: ['reset-regression-qc'],
mutationFn: async () => 'ok',
});

await mutation.mutate();
expect(mutation.result.status).toBe('success');
mutation.destroy();
expect(mutation.result.status).toBe('idle');
});

it('config.resetOnDestroy true wins over qc.mutationFeatures.resetOnDispose', async () => {
const queryClient = new MobxQueryClient({
defaultOptions: {
mutations: {
resetOnDestroy: false,
resetOnDispose: true,
} as MobxQueryClient['mutationFeatures'],
},
});

const mutation = new Mutation({
queryClient,
mutationKey: ['reset-regression-both'],
mutationFn: async () => 'ok',
resetOnDestroy: true,
});

await mutation.mutate();
expect(mutation.result.status).toBe('success');
mutation.destroy();
expect(mutation.result.status).toBe('idle');
});

it('explicit config.resetOnDestroy false overrides qc.mutationFeatures.resetOnDestroy', async () => {
const queryClient = new MobxQueryClient({
defaultOptions: {
mutations: { resetOnDestroy: true },
},
});

const mutation = new Mutation({
queryClient,
mutationKey: ['reset-regression-config-false'],
mutationFn: async () => 'ok',
resetOnDestroy: false,
});

await mutation.mutate();
expect(mutation.result.status).toBe('success');
mutation.destroy();
expect(mutation.result.status).toBe('success');
});
});
});
Loading
Loading