Skip to content
Merged
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
2 changes: 1 addition & 1 deletion examples/nuxt-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"precommit": "npm run lint"
},
"dependencies": {
"@nuxtjs/composition-api": "^0.24.4",
"@nuxtjs/composition-api": "^0.28.0",
"nuxt": "^2.0.0",
"vue-query": "^1.5.1"
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"vue-demi": "0.10.1"
},
"peerDependencies": {
"@nuxtjs/composition-api": "^0.24.4",
"@vue/composition-api": "^1.0.0",
"@nuxtjs/composition-api": "^0.28.0",
"@vue/composition-api": "^1.1.2",
"vue": "^2.0.0 || >=3.0.0"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion src/__mocks__/vue-demi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module.exports = {
...vue,
inject: jest.fn(),
provide: jest.fn(),
onUnmounted: jest.fn(),
onScopeDispose: jest.fn(),
getCurrentInstance: jest.fn(() => ({ proxy: {} })),
};
14 changes: 7 additions & 7 deletions src/vue/__tests__/useIsFetching.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onUnmounted } from "vue-demi";
import { onScopeDispose } from "vue-demi";
import { setLogger } from "react-query/core";

import { flushPromises, simpleFetcher, noop } from "./test-utils";
Expand Down Expand Up @@ -33,13 +33,13 @@ describe("useIsFetching", () => {
expect(isFetching.value).toStrictEqual(0);
});

test("should stop listening to changes on onUnmount", async () => {
const onUnmountedMock = onUnmounted as jest.MockedFunction<
typeof onUnmounted
test("should stop listening to changes on onScopeDispose", async () => {
const onScopeDisposeMock = onScopeDispose as jest.MockedFunction<
typeof onScopeDispose
>;
onUnmountedMock.mockImplementation((fn) => fn());
onScopeDisposeMock.mockImplementation((fn) => fn());

const { status } = useQuery("onUnmounted", simpleFetcher);
const { status } = useQuery("onScopeDispose", simpleFetcher);
const isFetching = useIsFetching();

expect(status.value).toStrictEqual("loading");
Expand All @@ -55,6 +55,6 @@ describe("useIsFetching", () => {
expect(status.value).toStrictEqual("loading");
expect(isFetching.value).toStrictEqual(1);

onUnmountedMock.mockReset();
onScopeDisposeMock.mockReset();
});
});
12 changes: 6 additions & 6 deletions src/vue/__tests__/useIsMutating.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onUnmounted } from "vue-demi";
import { onScopeDispose } from "vue-demi";
import { setLogger } from "react-query/core";

import { flushPromises, noop, successMutator } from "./test-utils";
Expand Down Expand Up @@ -36,11 +36,11 @@ describe("useIsMutating", () => {
expect(isMutating.value).toStrictEqual(0);
});

test("should stop listening to changes on onUnmount", async () => {
const onUnmountedMock = onUnmounted as jest.MockedFunction<
typeof onUnmounted
test("should stop listening to changes on onScopeDispose", async () => {
const onScopeDisposeMock = onScopeDispose as jest.MockedFunction<
typeof onScopeDispose
>;
onUnmountedMock.mockImplementation((fn) => fn());
onScopeDisposeMock.mockImplementation((fn) => fn());

const mutation = useMutation((params: string) => successMutator(params));
const mutation2 = useMutation((params: string) => successMutator(params));
Expand All @@ -59,7 +59,7 @@ describe("useIsMutating", () => {

expect(isMutating.value).toStrictEqual(0);

onUnmountedMock.mockReset();
onScopeDisposeMock.mockReset();
});

test("should call `useQueryClient` with a proper `queryClientKey`", async () => {
Expand Down
10 changes: 5 additions & 5 deletions src/vue/__tests__/useQueries.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onUnmounted, reactive } from "vue-demi";
import { onScopeDispose, reactive } from "vue-demi";
import { setLogger } from "react-query/core";

import {
Expand Down Expand Up @@ -166,11 +166,11 @@ describe("useQueries", () => {
]);
});

test("should stop listening to changes on onUnmount", async () => {
const onUnmountedMock = onUnmounted as jest.MockedFunction<
typeof onUnmounted
test("should stop listening to changes on onScopeDispose", async () => {
const onScopeDisposeMock = onScopeDispose as jest.MockedFunction<
typeof onScopeDispose
>;
onUnmountedMock.mockImplementationOnce((fn) => fn());
onScopeDisposeMock.mockImplementationOnce((fn) => fn());

const queries = [
{
Expand Down
12 changes: 6 additions & 6 deletions src/vue/__tests__/useQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
computed,
reactive,
ref,
onUnmounted,
onScopeDispose,
getCurrentInstance,
} from "vue-demi";
import { QueryObserver, setLogger } from "react-query/core";
Expand Down Expand Up @@ -214,13 +214,13 @@ describe("useQuery", () => {
expect(status.value).toStrictEqual("success");
});

test("should stop listening to changes on onUnmount", async () => {
const onUnmountedMock = onUnmounted as jest.MockedFunction<
typeof onUnmounted
test("should stop listening to changes on onScopeDispose", async () => {
const onScopeDisposeMock = onScopeDispose as jest.MockedFunction<
typeof onScopeDispose
>;
onUnmountedMock.mockImplementationOnce((fn) => fn());
onScopeDisposeMock.mockImplementationOnce((fn) => fn());

const { status } = useQuery("onUnmounted", simpleFetcher);
const { status } = useQuery("onScopeDispose", simpleFetcher);

expect(status.value).toStrictEqual("loading");

Expand Down
8 changes: 4 additions & 4 deletions src/vue/__tests__/useQueryProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { provide, onUnmounted } from "vue-demi";
import { provide, onScopeDispose } from "vue-demi";
import { QueryClient } from "../queryClient";

import { useQueryProvider } from "../useQueryProvider";
Expand All @@ -10,7 +10,7 @@ jest.mock("../queryClient", () => ({

describe("useQueryProvider", () => {
const provideSpy = provide as jest.Mock;
const onUnmountedSpy = onUnmounted as jest.Mock;
const onScopeDisposeSpy = onScopeDispose as jest.Mock;
const queryClientSpy = QueryClient as jest.Mock;

const mount = jest.fn();
Expand Down Expand Up @@ -74,8 +74,8 @@ describe("useQueryProvider", () => {
);
});

test("should call unmount on QueryClient", () => {
onUnmountedSpy.mockImplementationOnce((fn) => fn());
test("should call onScopeDispose on QueryClient", () => {
onScopeDisposeSpy.mockImplementationOnce((fn) => fn());

useQueryProvider();

Expand Down
4 changes: 2 additions & 2 deletions src/vue/useBaseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
onUnmounted,
onScopeDispose,
toRefs,
readonly,
ToRefs,
Expand Down Expand Up @@ -71,7 +71,7 @@ export function useBaseQuery<
{ deep: true }
);

onUnmounted(() => {
onScopeDispose(() => {
unsubscribe();
});

Expand Down
4 changes: 2 additions & 2 deletions src/vue/useIsFetching.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onUnmounted, Ref, ref, watchEffect } from "vue-demi";
import { onScopeDispose, Ref, ref, watchEffect } from "vue-demi";
import type { QueryKey } from "react-query/types/core";
import type { QueryFilters as QF } from "react-query/types/core/utils";

Expand Down Expand Up @@ -34,7 +34,7 @@ export function useIsFetching(
filters.value = parsedFiltersUpdate;
});

onUnmounted(() => {
onScopeDispose(() => {
unsubscribe();
});

Expand Down
4 changes: 2 additions & 2 deletions src/vue/useIsMutating.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onUnmounted, Ref, ref } from "vue-demi";
import { onScopeDispose, Ref, ref } from "vue-demi";
import type { MutationKey } from "react-query/types/core";
import type { MutationFilters as MF } from "react-query/types/core/utils";

Expand Down Expand Up @@ -26,7 +26,7 @@ export function useIsMutating(
isMutating.value = queryClient.isMutating(filters);
});

onUnmounted(() => {
onScopeDispose(() => {
unsubscribe();
});

Expand Down
4 changes: 2 additions & 2 deletions src/vue/useMutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
onUnmounted,
onScopeDispose,
reactive,
watchEffect,
readonly,
Expand Down Expand Up @@ -134,7 +134,7 @@ export function useMutation<
observer.setOptions(options);
});

onUnmounted(() => {
onScopeDispose(() => {
unsubscribe();
});

Expand Down
4 changes: 2 additions & 2 deletions src/vue/useQueries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { QueriesObserver } from "react-query/core";
import {
onUnmounted,
onScopeDispose,
reactive,
readonly,
watch,
Expand Down Expand Up @@ -164,7 +164,7 @@ export function useQueries<T extends any[]>(
});
}

onUnmounted(() => {
onScopeDispose(() => {
unsubscribe();
});

Expand Down
4 changes: 2 additions & 2 deletions src/vue/useQueryProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { provide, onUnmounted } from "vue-demi";
import { provide, onScopeDispose } from "vue-demi";
import type { QueryClientConfig } from "react-query/types/core";
import { QueryClient } from "./queryClient";
import { getClientKey } from "./utils";
Expand All @@ -15,7 +15,7 @@ export function useQueryProvider(
const key = getClientKey(id);
provide(key, client);

onUnmounted(() => {
onScopeDispose(() => {
client.unmount();
});
}