From 243743c74b4c2aabf8562fed51ef57f7b2aeb378 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 16 Oct 2023 17:56:03 +0800 Subject: [PATCH 1/6] docs: update changelog [skip ci] --- CHANGELOG.md | 4 ++-- CHANGELOG.zh-CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8211cb..21ff4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,8 @@ All notable changes to this project will be documented in this file. See [standa ### Refactor -- `useRequest` 支持传入自定义插件 [#204](https://github.com/attojs/vue-request/issues/204) ([3280f44](https://github.com/attojs/vue-request/commit/3280f4402728252e0154e22140c5a3913d407823)) -- 导出部分缺失的类型 [#215](https://github.com/attojs/vue-request/issues/215) [#217](https://github.com/attojs/vue-request/issues/217) ([35b07a4](https://github.com/attojs/vue-request/commit/35b07a4ffa22aca2cac3d1c46a0f4b99e4d1f206)) +- `useRequest` supports passing custom plugins [#204](https://github.com/attojs/vue-request/issues/204) ([3280f44](https://github.com/attojs/vue-request/commit/3280f4402728252e0154e22140c5a3913d407823)) +- expose some types [#215](https://github.com/attojs/vue-request/issues/215) [#217](https://github.com/attojs/vue-request/issues/217) ([35b07a4](https://github.com/attojs/vue-request/commit/35b07a4ffa22aca2cac3d1c46a0f4b99e4d1f206)) ### [2.0.3](https://github.com/attojs/vue-request/compare/v2.0.2...v2.0.3) (2023-06-13) diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index ba64ecd..2225572 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -6,8 +6,8 @@ All notable changes to this project will be documented in this file. See [standa ### Refactor -- `useRequest` supports passing custom plugins [#204](https://github.com/attojs/vue-request/issues/204) ([3280f44](https://github.com/attojs/vue-request/commit/3280f4402728252e0154e22140c5a3913d407823)) -- expose some types [#215](https://github.com/attojs/vue-request/issues/215) [#217](https://github.com/attojs/vue-request/issues/217) ([35b07a4](https://github.com/attojs/vue-request/commit/35b07a4ffa22aca2cac3d1c46a0f4b99e4d1f206)) +- `useRequest` 支持传入自定义插件 [#204](https://github.com/attojs/vue-request/issues/204) ([3280f44](https://github.com/attojs/vue-request/commit/3280f4402728252e0154e22140c5a3913d407823)) +- 导出部分缺失的类型 [#215](https://github.com/attojs/vue-request/issues/215) [#217](https://github.com/attojs/vue-request/issues/217) ([35b07a4](https://github.com/attojs/vue-request/commit/35b07a4ffa22aca2cac3d1c46a0f4b99e4d1f206)) ### [2.0.3](https://github.com/attojs/vue-request/compare/v2.0.2...v2.0.3) (2023-06-13) From e64e31e20dd6e0fc3d0dc5855bd26f9f0dee6615 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 10 Jan 2024 18:21:57 +0800 Subject: [PATCH 2/6] refactor: optimize the `onBefore` hook in custom plugins #226 Add `isReturn` to handle situations where the request needs to be aborted and custom data returned. --- src/core/createQuery.ts | 25 ++++++++++++++++++----- src/core/plugins/useCachePlugin.ts | 11 +++++----- src/core/plugins/useLoadingDelayPlugin.ts | 4 +++- src/core/plugins/useReadyPlugin.ts | 1 - src/core/types.ts | 12 ++++++----- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/core/createQuery.ts b/src/core/createQuery.ts index 7ac594e..a30d8e3 100644 --- a/src/core/createQuery.ts +++ b/src/core/createQuery.ts @@ -19,7 +19,9 @@ const setStateBind = ( ) => { return (newState: Partial>) => { Object.keys(newState).forEach(key => { - oldState[key].value = newState[key]; + if (oldState[key]) { + oldState[key].value = newState[key]; + } }); publicCb.forEach(fun => fun(oldState)); }; @@ -80,18 +82,31 @@ const createQuery = ( context.runAsync = async (...args: P): Promise => { setState({ - loading: true, - params: args, status: 'pending', }); count.value += 1; const currentCount = count.value; - const { isBreak, breakResult = resolvedPromise() } = emit('onBefore', args); + const { + isBreak = false, + isReturn = false, + ...rest + } = emit('onBefore', args); if (isBreak) { setState({ status: 'settled' }); - return breakResult; + return resolvedPromise(); + } + + setState({ + loading: true, + params: args, + ...rest, + }); + + if (isReturn) { + setState({ status: 'settled', loading: false }); + return rest.data!; } onBefore?.(args); diff --git a/src/core/plugins/useCachePlugin.ts b/src/core/plugins/useCachePlugin.ts index cb42c5f..3d3ad95 100644 --- a/src/core/plugins/useCachePlugin.ts +++ b/src/core/plugins/useCachePlugin.ts @@ -82,15 +82,16 @@ export default definePlugin( } // If it's fresh, stop the request if (isFresh(cache.time)) { - queryInstance.data.value = cache.data; - queryInstance.loading.value = false; return { - isBreak: true, - breakResult: cache.data, + isReturn: true, + loading: false, + data: cache.data, }; } else { // If it is not fresh, set data and request - queryInstance.data.value = cache.data; + return { + data: cache.data, + }; } }, onQuery(service) { diff --git a/src/core/plugins/useLoadingDelayPlugin.ts b/src/core/plugins/useLoadingDelayPlugin.ts index f95c26c..507c5c6 100644 --- a/src/core/plugins/useLoadingDelayPlugin.ts +++ b/src/core/plugins/useLoadingDelayPlugin.ts @@ -49,10 +49,12 @@ export default definePlugin( }; return { onBefore() { - queryInstance.loading.value = !loadingDelayRef.value; delayLoadingTimer.value(); delayLoadingTimer.value = delayLoading(); startTime = getCurrentTime(); + return { + loading: !loadingDelayRef.value, + }; }, onQuery(service) { if (!loadingKeepRef.value) return () => service(); diff --git a/src/core/plugins/useReadyPlugin.ts b/src/core/plugins/useReadyPlugin.ts index 44e17b1..ae6ce34 100644 --- a/src/core/plugins/useReadyPlugin.ts +++ b/src/core/plugins/useReadyPlugin.ts @@ -21,7 +21,6 @@ export default definePlugin( onBefore() { const readyFlag = isFunction(ready) ? ready() : ready.value; if (!readyFlag) { - queryInstance.loading.value = false; return { isBreak: true, }; diff --git a/src/core/types.ts b/src/core/types.ts index 3302f4e..be4acf5 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -4,7 +4,7 @@ import type { Ref, WatchSource } from 'vue-demi'; import type { PaginationExtendsOption } from '../usePagination'; import type { CacheData } from './utils/cache'; -import type { EmitVoid } from './utils/types'; +import type { EmitVoid, UnWrapRefObject } from './utils/types'; type MutateData = (newData: R) => void; type MutateFunction = (arg: (oldData: R) => R) => void; @@ -91,10 +91,12 @@ export type PluginImplementType = { }; export type PluginType = { - onBefore: (params: P) => { - isBreak?: Boolean; - breakResult?: any; - } | void; + onBefore: (params: P) => + | ({ + isBreak?: Boolean; + isReturn?: Boolean; + } & Partial>>) + | void; onQuery: (service: () => Promise) => () => Promise; From 9c951990e711bb4deabc54e01db232a3fdd0c642 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 10 Dec 2024 15:41:56 +0800 Subject: [PATCH 3/6] refactor: use `onScopeDispose` instead of `onUnmounted`. #239 --- package.json | 2 +- src/core/plugins/useCachePlugin.ts | 6 +- src/core/plugins/usePollingPlugin.ts | 12 +- src/core/plugins/useRefreshOnWindowFocus.ts | 6 +- src/core/useQuery.ts | 16 +- src/core/utils/index.ts | 10 + yarn.lock | 195 ++++++++++++++++---- 7 files changed, 193 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index 3a900c4..aa950a1 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "typescript": "^4.0.5", "vite": "^2.1.5", "vite-plugin-vue2": "^1.9.2", - "vue": "^3.3.4", + "vue": "^3.5.13", "vue-template-compiler": "^2.6.14", "vue2": "npm:vue@2" }, diff --git a/src/core/plugins/useCachePlugin.ts b/src/core/plugins/useCachePlugin.ts index 3d3ad95..3ee0e6a 100644 --- a/src/core/plugins/useCachePlugin.ts +++ b/src/core/plugins/useCachePlugin.ts @@ -1,7 +1,7 @@ -import { onUnmounted, ref } from 'vue-demi'; +import { ref } from 'vue-demi'; import { definePlugin } from '../definePlugin'; -import { isFunction } from '../utils'; +import { isFunction, onScopeDisposeCompatible } from '../utils'; import type { CacheData } from '../utils/cache'; import { getCache, setCache } from '../utils/cache'; import { getCacheQuery, setCacheQuery } from '../utils/cacheQuery'; @@ -68,7 +68,7 @@ export default definePlugin( unSubscribe.value = subscribeCache(); } - onUnmounted(() => { + onScopeDisposeCompatible(() => { unSubscribe.value(); }); diff --git a/src/core/plugins/usePollingPlugin.ts b/src/core/plugins/usePollingPlugin.ts index 22f874b..06d5b4c 100644 --- a/src/core/plugins/usePollingPlugin.ts +++ b/src/core/plugins/usePollingPlugin.ts @@ -1,7 +1,13 @@ -import { computed, onUnmounted, ref, watch } from 'vue-demi'; +import { computed, ref, watch } from 'vue-demi'; import { definePlugin } from '../definePlugin'; -import { isDocumentVisibility, isNil, isOnline, refToRaw } from '../utils'; +import { + isDocumentVisibility, + isNil, + isOnline, + onScopeDisposeCompatible, + refToRaw, +} from '../utils'; import subscriber from '../utils/listener'; import type { Timeout } from '../utils/types'; @@ -76,7 +82,7 @@ export default definePlugin( addUnsubscribeList(subscriber('RECONNECT_LISTENER', rePolling)); } - onUnmounted(() => { + onScopeDisposeCompatible(() => { unsubscribeList.forEach(unsubscribe => unsubscribe()); }); diff --git a/src/core/plugins/useRefreshOnWindowFocus.ts b/src/core/plugins/useRefreshOnWindowFocus.ts index cd3484c..e46365b 100644 --- a/src/core/plugins/useRefreshOnWindowFocus.ts +++ b/src/core/plugins/useRefreshOnWindowFocus.ts @@ -1,7 +1,7 @@ -import { computed, onUnmounted, watchEffect } from 'vue-demi'; +import { computed, watchEffect } from 'vue-demi'; import { definePlugin } from '../definePlugin'; -import { refToRaw } from '../utils'; +import { onScopeDisposeCompatible, refToRaw } from '../utils'; import limitTrigger from '../utils/limitTrigger'; import subscriber from '../utils/listener'; @@ -32,7 +32,7 @@ export default definePlugin( } }); - onUnmounted(() => { + onScopeDisposeCompatible(() => { unsubscribe(); }); diff --git a/src/core/useQuery.ts b/src/core/useQuery.ts index 04261d4..9c81f67 100644 --- a/src/core/useQuery.ts +++ b/src/core/useQuery.ts @@ -1,4 +1,4 @@ -import { inject, onUnmounted } from 'vue-demi'; +import { getCurrentInstance, inject } from 'vue-demi'; import { getGlobalOptions, GLOBAL_OPTIONS_PROVIDE_KEY } from './config'; import createQuery from './createQuery'; @@ -9,16 +9,20 @@ import type { QueryResult, Service, } from './types'; +import { onScopeDisposeCompatible } from './utils'; function useQuery( service: Service, options: Options = {}, plugins: PluginImplementType[], ): QueryResult { - const injectedGlobalOptions = inject( - GLOBAL_OPTIONS_PROVIDE_KEY, - {}, - ); + let injectedGlobalOptions = {}; + if (getCurrentInstance()) { + injectedGlobalOptions = inject( + GLOBAL_OPTIONS_PROVIDE_KEY, + {}, + ); + } const config = { ...getGlobalOptions(), @@ -38,7 +42,7 @@ function useQuery( queryInstance.context.run(...params); } - onUnmounted(() => { + onScopeDisposeCompatible(() => { queryInstance.context.cancel(); }); diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index 19463bb..4314072 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -1,4 +1,5 @@ import type { Ref } from 'vue-demi'; +import { onScopeDispose, version } from 'vue-demi'; import { isRef } from 'vue-demi'; export const objectToString = Object.prototype.toString; @@ -80,3 +81,12 @@ export const shallowCopy = (value: T): T => { return value; } }; + +export const onScopeDisposeCompatible = (fn: () => void) => { + if (version.startsWith('3.5')) { + // @ts-ignore + onScopeDispose(fn, true); + } else { + onScopeDispose(fn); + } +}; diff --git a/yarn.lock b/yarn.lock index 46eb7c9..2687e51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -236,6 +236,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.21.5.tgz#2b3eea65443c6bdc31c22d037c65f6d323b6b2bd" integrity sha512-5pTUx3hAJaZIdW99sJ6ZUUgWq/Y+Hja7TowEnLNMm1VivRgZQL3vpBY3qUACVsvw+yQU6+YgfBVmcbLaZtrA1w== +"@babel/helper-string-parser@^7.25.9": + version "7.25.9" + resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz#1aabb72ee72ed35789b4bbcad3ca2862ce614e8c" + integrity sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA== + "@babel/helper-validator-identifier@^7.18.6", "@babel/helper-validator-identifier@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193" @@ -246,6 +251,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2" integrity sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w== +"@babel/helper-validator-identifier@^7.25.9": + version "7.25.9" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz#24b64e2c3ec7cd3b3c547729b8d16871f22cbdc7" + integrity sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ== + "@babel/helper-validator-option@^7.21.0": version "7.21.0" resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.21.0.tgz#8224c7e13ace4bafdc4004da2cf064ef42673180" @@ -293,6 +303,13 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.4.tgz#a770e98fd785c231af9d93f6459d36770993fb32" integrity sha512-VLLsx06XkEYqBtE5YGPwfSGwfrjnyPP5oiGty3S8pQLFDFLaS8VwWSIxkTXpcvr5zeYLE6+MBNl2npl/YnfofA== +"@babel/parser@^7.25.3": + version "7.26.3" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.26.3.tgz#8c51c5db6ddf08134af1ddbacf16aaab48bac234" + integrity sha512-WJ/CvmY8Mea8iDXo6a7RK2wbmJITT5fN3BEkRuFlxVyNx8jOKIIhmC4fSkTcPcf8JyavbBwIe6OpiCOBXt/IcA== + dependencies: + "@babel/types" "^7.26.3" + "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@^7.18.6": version "7.18.6" resolved "https://registry.yarnpkg.com/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.18.6.tgz#da5b8f9a580acdfbe53494dba45ea389fb09a4d2" @@ -1079,6 +1096,14 @@ "@babel/helper-validator-identifier" "^7.19.1" to-fast-properties "^2.0.0" +"@babel/types@^7.26.3": + version "7.26.3" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.26.3.tgz#37e79830f04c2b5687acc77db97fbc75fb81f3c0" + integrity sha512-vN5p+1kl59GVKMvTHt55NzzmYVxprfJD+ql7U9NFIfKCBkYE55LYtS+WtPlaYOyzydrKI8Nezd+aZextrd+FMA== + dependencies: + "@babel/helper-string-parser" "^7.25.9" + "@babel/helper-validator-identifier" "^7.25.9" + "@bcoe/v8-coverage@^0.2.3": version "0.2.3" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" @@ -1490,6 +1515,11 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== +"@jridgewell/sourcemap-codec@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a" + integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ== + "@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.9": version "0.3.18" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz#25783b2086daf6ff1dcb53c9249ae480e4dd4cd6" @@ -2032,6 +2062,17 @@ estree-walker "^2.0.2" source-map-js "^1.0.2" +"@vue/compiler-core@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.5.13.tgz#b0ae6c4347f60c03e849a05d34e5bf747c9bda05" + integrity sha512-oOdAkwqUfW1WqpwSYJce06wvt6HljgY3fGeM9NcVA1HaYOij3mZG9Rkysn0OHuyUAGMbEbARIpsG+LPVlBJ5/Q== + dependencies: + "@babel/parser" "^7.25.3" + "@vue/shared" "3.5.13" + entities "^4.5.0" + estree-walker "^2.0.2" + source-map-js "^1.2.0" + "@vue/compiler-dom@3.3.4": version "3.3.4" resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.3.4.tgz#f56e09b5f4d7dc350f981784de9713d823341151" @@ -2040,6 +2081,14 @@ "@vue/compiler-core" "3.3.4" "@vue/shared" "3.3.4" +"@vue/compiler-dom@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.5.13.tgz#bb1b8758dbc542b3658dda973b98a1c9311a8a58" + integrity sha512-ZOJ46sMOKUjO3e94wPdCzQ6P1Lx/vhp2RSvfaab88Ajexs0AHeV0uasYhi99WPaogmBlRHNRuly8xV75cNTMDA== + dependencies: + "@vue/compiler-core" "3.5.13" + "@vue/shared" "3.5.13" + "@vue/compiler-sfc@2.7.14": version "2.7.14" resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-2.7.14.tgz#3446fd2fbb670d709277fc3ffa88efc5e10284fd" @@ -2049,7 +2098,22 @@ postcss "^8.4.14" source-map "^0.6.1" -"@vue/compiler-sfc@3.3.4", "@vue/compiler-sfc@^3.0.6": +"@vue/compiler-sfc@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.5.13.tgz#461f8bd343b5c06fac4189c4fef8af32dea82b46" + integrity sha512-6VdaljMpD82w6c2749Zhf5T9u5uLBWKnVue6XWxprDobftnletJ8+oel7sexFfM3qIxNmVE7LSFGTpv6obNyaQ== + dependencies: + "@babel/parser" "^7.25.3" + "@vue/compiler-core" "3.5.13" + "@vue/compiler-dom" "3.5.13" + "@vue/compiler-ssr" "3.5.13" + "@vue/shared" "3.5.13" + estree-walker "^2.0.2" + magic-string "^0.30.11" + postcss "^8.4.48" + source-map-js "^1.2.0" + +"@vue/compiler-sfc@^3.0.6": version "3.3.4" resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.3.4.tgz#b19d942c71938893535b46226d602720593001df" integrity sha512-6y/d8uw+5TkCuzBkgLS0v3lSM3hJDntFEiUORM11pQ/hKvkhSKZrXW6i69UyXlJQisJxuUEJKAWEqWbWsLeNKQ== @@ -2073,6 +2137,14 @@ "@vue/compiler-dom" "3.3.4" "@vue/shared" "3.3.4" +"@vue/compiler-ssr@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.5.13.tgz#e771adcca6d3d000f91a4277c972a996d07f43ba" + integrity sha512-wMH6vrYHxQl/IybKJagqbquvxpWCuVYpoUJfCqFZwa/JY1GdATAQ+TgVtgrwwMZ0D07QhA99rs/EAAWfvG6KpA== + dependencies: + "@vue/compiler-dom" "3.5.13" + "@vue/shared" "3.5.13" + "@vue/component-compiler-utils@^3.2.2": version "3.3.0" resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-3.3.0.tgz#f9f5fb53464b0c37b2c8d2f3fbfe44df60f61dc9" @@ -2105,43 +2177,49 @@ estree-walker "^2.0.2" magic-string "^0.30.0" -"@vue/reactivity@3.3.4": - version "3.3.4" - resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.3.4.tgz#a27a29c6cd17faba5a0e99fbb86ee951653e2253" - integrity sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ== +"@vue/reactivity@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/reactivity/-/reactivity-3.5.13.tgz#b41ff2bb865e093899a22219f5b25f97b6fe155f" + integrity sha512-NaCwtw8o48B9I6L1zl2p41OHo/2Z4wqYGGIK1Khu5T7yxrn+ATOixn/Udn2m+6kZKB/J7cuT9DbWWhRxqixACg== dependencies: - "@vue/shared" "3.3.4" + "@vue/shared" "3.5.13" -"@vue/runtime-core@3.3.4": - version "3.3.4" - resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.3.4.tgz#4bb33872bbb583721b340f3088888394195967d1" - integrity sha512-R+bqxMN6pWO7zGI4OMlmvePOdP2c93GsHFM/siJI7O2nxFRzj55pLwkpCedEY+bTMgp5miZ8CxfIZo3S+gFqvA== +"@vue/runtime-core@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/runtime-core/-/runtime-core-3.5.13.tgz#1fafa4bf0b97af0ebdd9dbfe98cd630da363a455" + integrity sha512-Fj4YRQ3Az0WTZw1sFe+QDb0aXCerigEpw418pw1HBUKFtnQHWzwojaukAs2X/c9DQz4MQ4bsXTGlcpGxU/RCIw== dependencies: - "@vue/reactivity" "3.3.4" - "@vue/shared" "3.3.4" + "@vue/reactivity" "3.5.13" + "@vue/shared" "3.5.13" -"@vue/runtime-dom@3.3.4": - version "3.3.4" - resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.3.4.tgz#992f2579d0ed6ce961f47bbe9bfe4b6791251566" - integrity sha512-Aj5bTJ3u5sFsUckRghsNjVTtxZQ1OyMWCr5dZRAPijF/0Vy4xEoRCwLyHXcj4D0UFbJ4lbx3gPTgg06K/GnPnQ== +"@vue/runtime-dom@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/runtime-dom/-/runtime-dom-3.5.13.tgz#610fc795de9246300e8ae8865930d534e1246215" + integrity sha512-dLaj94s93NYLqjLiyFzVs9X6dWhTdAlEAciC3Moq7gzAc13VJUdCnjjRurNM6uTLFATRHexHCTu/Xp3eW6yoog== dependencies: - "@vue/runtime-core" "3.3.4" - "@vue/shared" "3.3.4" - csstype "^3.1.1" + "@vue/reactivity" "3.5.13" + "@vue/runtime-core" "3.5.13" + "@vue/shared" "3.5.13" + csstype "^3.1.3" -"@vue/server-renderer@3.3.4": - version "3.3.4" - resolved "https://registry.yarnpkg.com/@vue/server-renderer/-/server-renderer-3.3.4.tgz#ea46594b795d1536f29bc592dd0f6655f7ea4c4c" - integrity sha512-Q6jDDzR23ViIb67v+vM1Dqntu+HUexQcsWKhhQa4ARVzxOY2HbC7QRW/ggkDBd5BU+uM1sV6XOAP0b216o34JQ== +"@vue/server-renderer@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/server-renderer/-/server-renderer-3.5.13.tgz#429ead62ee51de789646c22efe908e489aad46f7" + integrity sha512-wAi4IRJV/2SAW3htkTlB+dHeRmpTiVIK1OGLWV1yeStVSebSQQOwGwIq0D3ZIoBj2C2qpgz5+vX9iEBkTdk5YA== dependencies: - "@vue/compiler-ssr" "3.3.4" - "@vue/shared" "3.3.4" + "@vue/compiler-ssr" "3.5.13" + "@vue/shared" "3.5.13" "@vue/shared@3.3.4": version "3.3.4" resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.3.4.tgz#06e83c5027f464eef861c329be81454bc8b70780" integrity sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ== +"@vue/shared@3.5.13": + version "3.5.13" + resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.5.13.tgz#87b309a6379c22b926e696893237826f64339b6f" + integrity sha512-/hnE/qP5ZoGpol0a5mDi45bOd7t3tjYJBjsgCsivow7D48cJeV5l05RD82lPqi7gRiphZM37rnhW1l6ZoCNNnQ== + "@yarnpkg/lockfile@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" @@ -3260,11 +3338,16 @@ cssstyle@^2.3.0: dependencies: cssom "~0.3.6" -csstype@^3.1.0, csstype@^3.1.1: +csstype@^3.1.0: version "3.1.2" resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b" integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ== +csstype@^3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81" + integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw== + dargs@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc" @@ -3531,6 +3614,11 @@ enquirer@^2.3.5, enquirer@^2.3.6: dependencies: ansi-colors "^4.1.1" +entities@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48" + integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw== + error-ex@^1.3.1: version "1.3.2" resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" @@ -5925,6 +6013,13 @@ magic-string@^0.30.0: dependencies: "@jridgewell/sourcemap-codec" "^1.4.13" +magic-string@^0.30.11: + version "0.30.14" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.14.tgz#e9bb29870b81cfc1ec3cc656552f5a7fcbf19077" + integrity sha512-5c99P1WKTed11ZC0HMJOj6CDIue6F8ySu+bJL+85q1zBEIY8IklrJ1eiKC2NDRh3Ct3FcvmJPyQHb9erXMTJNw== + dependencies: + "@jridgewell/sourcemap-codec" "^1.5.0" + make-dir@^3.0.0, make-dir@^3.0.2: version "3.1.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" @@ -6126,6 +6221,11 @@ nanoid@^3.3.6: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c" integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA== +nanoid@^3.3.7: + version "3.3.8" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf" + integrity sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -6669,6 +6769,11 @@ picocolors@^1.0.0: resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== +picocolors@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b" + integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA== + picomatch@^2.0.4, picomatch@^2.2.2, picomatch@^2.2.3, picomatch@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" @@ -6735,6 +6840,15 @@ postcss@^8.1.10, postcss@^8.4.13, postcss@^8.4.14: picocolors "^1.0.0" source-map-js "^1.0.2" +postcss@^8.4.48: + version "8.4.49" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.49.tgz#4ea479048ab059ab3ae61d082190fabfd994fe19" + integrity sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA== + dependencies: + nanoid "^3.3.7" + picocolors "^1.1.1" + source-map-js "^1.2.1" + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" @@ -7446,6 +7560,11 @@ source-map-js@^1.0.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== +source-map-js@^1.2.0, source-map-js@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46" + integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA== + source-map-support@^0.5.6, source-map-support@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" @@ -8227,9 +8346,9 @@ vite@^2.1.5: fsevents "~2.3.2" vue-demi@latest: - version "0.14.5" - resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.5.tgz#676d0463d1a1266d5ab5cba932e043d8f5f2fbd9" - integrity sha512-o9NUVpl/YlsGJ7t+xuqJKx8EBGf1quRhCiT6D/J0pfwmk9zUwYkC7yrF4SZCe6fETvSM3UNL2edcbYrSyc4QHA== + version "0.14.10" + resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.10.tgz#afc78de3d6f9e11bf78c55e8510ee12814522f04" + integrity sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg== vue-eslint-parser@^7.10.0: version "7.11.0" @@ -8265,16 +8384,16 @@ vue-template-es2015-compiler@^1.9.0, vue-template-es2015-compiler@^1.9.1: "@vue/compiler-sfc" "2.7.14" csstype "^3.1.0" -vue@^3.3.4: - version "3.3.4" - resolved "https://registry.yarnpkg.com/vue/-/vue-3.3.4.tgz#8ed945d3873667df1d0fcf3b2463ada028f88bd6" - integrity sha512-VTyEYn3yvIeY1Py0WaYGZsXnz3y5UnGi62GjVEqvEGPl6nxbOrCXbVOTQWBEJUqAyTUk2uJ5JLVnYJ6ZzGbrSw== +vue@^3.5.13: + version "3.5.13" + resolved "https://registry.yarnpkg.com/vue/-/vue-3.5.13.tgz#9f760a1a982b09c0c04a867903fc339c9f29ec0a" + integrity sha512-wmeiSMxkZCSc+PM2w2VRsOYAZC8GdipNFRTsLSfodVqI9mbejKeXEGr8SckuLnrQPGe3oJN5c3K0vpoU9q/wCQ== dependencies: - "@vue/compiler-dom" "3.3.4" - "@vue/compiler-sfc" "3.3.4" - "@vue/runtime-dom" "3.3.4" - "@vue/server-renderer" "3.3.4" - "@vue/shared" "3.3.4" + "@vue/compiler-dom" "3.5.13" + "@vue/compiler-sfc" "3.5.13" + "@vue/runtime-dom" "3.5.13" + "@vue/server-renderer" "3.5.13" + "@vue/shared" "3.5.13" w3c-hr-time@^1.0.2: version "1.0.2" From 5973e83839663a68ff7e9f73b88eec1ca1898ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E4=B8=89?= Date: Tue, 10 Dec 2024 15:53:39 +0800 Subject: [PATCH 4/6] fix: memory leak when useing in ssr (#235) Co-authored-by: lijingfeng --- src/core/utils/listener.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/utils/listener.ts b/src/core/utils/listener.ts index 2cfea0b..ca5cd57 100644 --- a/src/core/utils/listener.ts +++ b/src/core/utils/listener.ts @@ -27,7 +27,9 @@ const subscriber = (listenerType: ListenerType, event: EventFunc) => { } if (listeners.has(event)) return; - listeners.add(event); + if (!isServer) { + listeners.add(event); + } return () => { listeners.delete(event); }; From f5d0050b9e9abf586ca76833ce105f3fcc5487fb Mon Sep 17 00:00:00 2001 From: John Date: Tue, 10 Dec 2024 16:36:56 +0800 Subject: [PATCH 5/6] fix: `injectedGlobalOptions` could be` undefined` in certain cases. #182 --- src/usePagination.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usePagination.ts b/src/usePagination.ts index 3727b6c..8df9981 100644 --- a/src/usePagination.ts +++ b/src/usePagination.ts @@ -58,7 +58,7 @@ function usePagination( const { currentKey, pageSizeKey, totalKey, totalPageKey } = merge( defaultPaginationOptions, getGlobalOptions().pagination || {}, - injectedGlobalOptions.pagination || {}, + injectedGlobalOptions?.pagination || {}, pagination || {}, ) as PaginationType; From dfe19e1acc24bd73981288fbf86137527fe13e91 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 14 Mar 2025 09:54:45 +0800 Subject: [PATCH 6/6] docs: update documents domain --- README-en_US.md | 10 +++++----- README.md | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README-en_US.md b/README-en_US.md index dd6678f..ebaa7ff 100644 --- a/README-en_US.md +++ b/README-en_US.md @@ -1,7 +1,7 @@ English | [简体中文](README.md)

- + ``` -In this example, `useRequest` receives a `service` function. `service` is an asynchronous request function, which means you can use **axios** to retrieve data and return a **Promise**. More specific details can be found in the [documentation](https://www.attojs.org/guide/documentation/dataFetching.html). +In this example, `useRequest` receives a `service` function. `service` is an asynchronous request function, which means you can use **axios** to retrieve data and return a **Promise**. More specific details can be found in the [documentation](https://www.attojs.com/guide/documentation/dataFetching.html). The `useRequest` function also returns three values: `data`, `loading`, and `error`. While the request is still in progress, `data` will be set to `undefined` and `loading` will be `true`. Once the request is completed, `data` and `error` will be set based on the result, and the page will be rendered accordingly. This is because `data`, `loading`, and `error` are [Reactivity(Refs)](https://vuejs.org/guide/essentials/reactivity-fundamentals.html) in Vue, and their values will be updated based on the request status and result. @@ -113,7 +113,7 @@ VueRequest provides many features, such as error retry, caching, pagination, thr ### 1.Refresh On Focus -Sometimes, you need to ensure data consistency across multiple browser windows or synchronize page data to the latest state when a user's computer resumes from sleep mode. Using `refreshOnWindowFocus` can save you a lot of logic code. [Click here to go to the document](https://www.attojs.org/guide/documentation/refreshOnWindowFocus.html) +Sometimes, you need to ensure data consistency across multiple browser windows or synchronize page data to the latest state when a user's computer resumes from sleep mode. Using `refreshOnWindowFocus` can save you a lot of logic code. [Click here to go to the document](https://www.attojs.com/guide/documentation/refreshOnWindowFocus.html) ```ts const { data, error, run } = useRequest(getUserInfo, { @@ -126,7 +126,7 @@ const { data, error, run } = useRequest(getUserInfo, { ### 2.Polling Data -Sometimes, you need to ensure data synchronization across multiple devices. In this case, you can use `pollingInterval` provided by us to periodically re-request the API, ensuring data consistency across multiple devices. When a user modifies the data, the changes will be synced in real-time between two windows. [Click here to go to the document](https://www.attojs.org/guide/documentation/polling.html) +Sometimes, you need to ensure data synchronization across multiple devices. In this case, you can use `pollingInterval` provided by us to periodically re-request the API, ensuring data consistency across multiple devices. When a user modifies the data, the changes will be synced in real-time between two windows. [Click here to go to the document](https://www.attojs.com/guide/documentation/polling.html) ```ts const { data, error, run } = useRequest(getUserInfo, { diff --git a/README.md b/README.md index c8e4765..d661aef 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ VueRequest 的目的是为开发人员提供一种方便、快速的方式来管 ## 文档 -- [English](https://www.attojs.org/) +- [English](https://en.attojs.com/) - [中文文档](https://www.attojs.com/) ## 安装 diff --git a/package.json b/package.json index aa950a1..2bfc92b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "vue-request", "vue request" ], - "homepage": "https://www.attojs.org", + "homepage": "https://www.attojs.com", "bugs": "https://github.com/attojs/vue-request/issues", "repository": { "type": "git",