diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000000000000000000000000000000000000..3d1f0e5fff5bca4bca8d111a2f188a35599097c0
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,13 @@
+# These are supported funding model platforms
+
+github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
+patreon: # Replace with a single Patreon username
+open_collective: # Replace with a single Open Collective username
+ko_fi: # Replace with a single Ko-fi username
+tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+liberapay: # Replace with a single Liberapay username
+issuehunt: # Replace with a single IssueHunt username
+otechie: # Replace with a single Otechie username
+lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
+custom: https://next.attojs.com/sponsor
diff --git a/README-zh_CN.md b/README-zh_CN.md
index 6d0fe6761f190eb024db9ad956dfe2dad0c3b24a..611e91b2613730b171368916dcc1bfe87caa2edc 100644
--- a/README-zh_CN.md
+++ b/README-zh_CN.md
@@ -38,6 +38,10 @@
+## 项目状态
+
+**v1 版本后续不会添加新的功能,只会对出现的 BUG 进行维护。想体验最新的功能,请切换到 v2 版本。v2 版本正在 RC 阶段,详情可以查看 [next](https://github.com/AttoJS/vue-request/blob/next/README-zh_CN.md) 分支。文档将随着正式版本发布。**
+
## 为什么选择 VueRequest
在以往的业务项目中,常常被 loading 状态的管理、请求的节流防抖、接口数据的缓存、分页等这些重复的实现所困惑。每当开启一个新项目时,我们都得手动去处理以上这些问题,这将是一个重复性的工作,而且还得确保团队的一致。
@@ -149,7 +153,7 @@ const { data, error, run } = useRequest(getUserInfo, {
如果你有很酷的想法,欢迎提交 issue 以便我们讨论
-- [ ] 支持 Vue 2
+- [x] 支持 Vue 2。详情请参阅 [next](https://github.com/AttoJS/vue-request/tree/next) 分支
- [x] 文档
- [x] 分页
- [x] 加载更多
diff --git a/README.md b/README.md
index 48fb4ea79d1b6ce670d774e61504f99e16fc4bbc..0593519ea298fc8cf804cf49542e347b3db0e632 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,10 @@ English | [简体中文](README-zh_CN.md)
+## Status
+
+**The v1 version will not add new functions in the future, and will only maintain the bugs that appear. To experience the latest features, please switch to the v2 version. The v2 version is in the RC stage. For details, you can check the [next](https://github.com/AttoJS/vue-request/blob/next/README.md) branch. Documentation will be released with the official release.**
+
## Why VueRequest
In the past projects, they were often confused by repeated implementations such as the management of the loading state, the requested throttling and debounce, the caching of request data, and pagination. Whenever we start a new project, we have to manually deal with the above problems, which will be a repetitive work, but also to ensure that the team is consistent.
@@ -148,7 +152,7 @@ const { data, error, run } = useRequest(getUserInfo, {
If you have any cool features, please submit an issue for discussion
-- [ ] Support Vue 2
+- [x] Support Vue 2. see [next](https://github.com/AttoJS/vue-request/tree/next) branch
- [x] Documentation
- [x] Pagination
- [x] Load More
diff --git a/package.json b/package.json
index 4552bb1d608153d1d77d08a086e13379a4c5e6ed..de0b5c16819b037af5dc84663be0471275bc0142 100644
--- a/package.json
+++ b/package.json
@@ -93,7 +93,7 @@
"rollup": "^2.33.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
- "simple-git": "^2.21.0",
+ "simple-git": "^3.3.0",
"sort-package-json": "^1.50.0",
"standard-version": "^9.1.1",
"ts-jest": "^26.4.1",
diff --git a/src/__tests__/index.test.tsx b/src/__tests__/index.test.tsx
index 8aad66b7c516950589e279ec650f57085a94f1f1..d7d042e3eef6f9e1adbc43aff8ab141c7e8bb92f 100644
--- a/src/__tests__/index.test.tsx
+++ b/src/__tests__/index.test.tsx
@@ -1759,6 +1759,60 @@ describe('useRequest', () => {
expect(mockFn).toHaveBeenCalledTimes(11);
});
+ test('errorRetry should work with debounce', async () => {
+ const wrapper = shallowMount(
+ defineComponent({
+ setup() {
+ const { run, loading, error } = useRequest(failedRequest, {
+ manual: true,
+ debounceInterval: 1000,
+ errorRetryCount: 4,
+ errorRetryInterval: 1000,
+ });
+ const handleClick = () => run();
+ return () => (
+
+ );
+ },
+ }),
+ );
+
+ // request
+ await wrapper.find('button').trigger('click');
+ await waitForTime(2001);
+ expect(wrapper.text()).toBe('fail');
+
+ // retrying 1
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('true');
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('fail');
+
+ // retrying 2
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('true');
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('fail');
+
+ // trigger button to reset retry count
+ await wrapper.find('button').trigger('click');
+ await waitForTime(2001);
+ expect(wrapper.text()).toBe('fail');
+
+ for (let index = 0; index < 4; index++) {
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('true');
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('fail');
+ }
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('fail');
+ await waitForTime(1000);
+ expect(wrapper.text()).toBe('fail');
+ });
+
test('errorRetry should work with pollingInterval', async () => {
let flag = true;
const mixinRequest = () => {
diff --git a/src/core/createQuery.ts b/src/core/createQuery.ts
index eadf7e90017b6056a6f29ffb295c8f91bfce3a69..05c382eacb4c770f96ada4494e2edc90f0fd93e6 100644
--- a/src/core/createQuery.ts
+++ b/src/core/createQuery.ts
@@ -232,6 +232,9 @@ const createQuery = (
const run = (...args: P) => {
clearAllTimer();
+
+ resetRetriedCount();
+
// initial auto run should not debounce
if (!initialAutoRunFlag.value && debouncedRun) {
debouncedRun(...args);
@@ -242,7 +245,6 @@ const createQuery = (
throttledRun(...args);
return resolvedPromise;
}
- resetRetriedCount();
return _run(...args);
};
diff --git a/src/usePagination.ts b/src/usePagination.ts
index 91378cdf45be991ec041cdde39cb3deee8dc6b3b..366de8c3db08b849baed6b2b0b3d1a9a89820f5a 100644
--- a/src/usePagination.ts
+++ b/src/usePagination.ts
@@ -151,7 +151,7 @@ function usePagination(
const total = computed(() => get(data.value!, totalKey, 0));
const current = computed({
get: () =>
- (params.value[0] as Record)?.[currentKey] ??
+ data.value?.[currentKey]??(params.value[0] as Record)?.[currentKey] ??
finallyOptions.defaultParams[0][currentKey],
set: (val: number) => {
changeCurrent(val);
@@ -159,7 +159,7 @@ function usePagination(
});
const pageSize = computed({
get: () =>
- (params.value[0] as Record)?.[pageSizeKey] ??
+ data.value?.[pageSizeKey]??(params.value[0] as Record)?.[pageSizeKey] ??
finallyOptions.defaultParams[0][pageSizeKey],
set: (val: number) => {
changePageSize(val);
diff --git a/yarn.lock b/yarn.lock
index 0866ea0cd2387ecb4cb3eda8cab30e21b4445353..e234486ee78cc1a110097b1d5164aea52542cb1a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3043,10 +3043,10 @@ debug@^2.2.0, debug@^2.3.3:
dependencies:
ms "2.0.0"
-debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1:
- version "4.3.1"
- resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
- integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
+debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.3:
+ version "4.3.4"
+ resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
+ integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"
@@ -3803,9 +3803,9 @@ flatted@^3.1.0:
integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA==
follow-redirects@^1.14.0:
- version "1.14.7"
- resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685"
- integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==
+ version "1.14.8"
+ resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
+ integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==
for-in@^1.0.2:
version "1.0.2"
@@ -5894,9 +5894,9 @@ minimist-options@4.1.0:
kind-of "^6.0.3"
minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
- version "1.2.5"
- resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
- integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
+ version "1.2.6"
+ resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
+ integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
mixin-deep@^1.2.0:
version "1.3.2"
@@ -7166,9 +7166,9 @@ semver-diff@^3.1.1:
semver "^6.3.0"
semver-regex@^3.1.2:
- version "3.1.3"
- resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.3.tgz#b2bcc6f97f63269f286994e297e229b6245d0dc3"
- integrity sha512-Aqi54Mk9uYTjVexLnR67rTyBusmwd04cLkHy9hNvk3+G3nT2Oyg7E0l4XVbOaNwIvQ3hHeYxGcyEy+mKreyBFQ==
+ version "3.1.4"
+ resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.4.tgz#13053c0d4aa11d070a2f2872b6b1e3ae1e1971b4"
+ integrity sha512-6IiqeZNgq01qGf0TId0t3NvKzSvUsjcpdEO3AQNeIjR6A2+ckTnQlDpl4qu1bjRv0RzN3FP9hzFmws3lKqRWkA==
"semver@2 || 3 || 4 || 5", semver@^5.5.0:
version "5.7.1"
@@ -7258,14 +7258,14 @@ signal-exit@^3.0.2, signal-exit@^3.0.3:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==
-simple-git@^2.21.0:
- version "2.38.0"
- resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-2.38.0.tgz#5bc66bec40bce4f8ef950f4966f427799b4dd758"
- integrity sha512-CORjrfirWMEGbJAxaXDH/PjZVOeATeG2bkafM9DsLVcFkbF9sXQGIIpEI6FeyXpvUsFK69T/pa4+4FKY9TUJMQ==
+simple-git@^3.3.0:
+ version "3.5.0"
+ resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-3.5.0.tgz#3c3538f4d7a1b3c8f3904412b12740bdcad9c8b1"
+ integrity sha512-fZsaq5nzdxQRhMNs6ESGLpMUHoL5GRP+boWPhq9pMYMKwOGZV2jHOxi8AbFFA2Y/6u4kR99HoULizSbpzaODkA==
dependencies:
"@kwsites/file-exists" "^1.1.1"
"@kwsites/promise-deferred" "^1.1.1"
- debug "^4.3.1"
+ debug "^4.3.3"
sisteransi@^1.0.5:
version "1.0.5"