Skip to content

Commit

Permalink
before reloading an Xhr query, if still in pending, abort it
Browse files Browse the repository at this point in the history
  • Loading branch information
tcastelly committed Oct 1, 2024
1 parent dfac98c commit 4081c6f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 88 deletions.
152 changes: 76 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"tsc:export-types": "tsc --outDir types"
},
"dependencies": {
"vue": "^3.5.4"
"vue": "^3.5.10"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
"babel-loader": "^9.2.1",
"babel-plugin-module-resolver": "^5.0.2",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand All @@ -49,8 +49,8 @@
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^15.2.10",
"typescript": "^5.6.2",
"vue": "^3.5.4",
"webpack": "^5.94.0",
"vue": "^3.5.10",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4"
},
"peerDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions src/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const useAsync = <T,
return null;
}

if (isPending.value) {
// @ts-ignore - the `abortXhr` can came from useXhr
d.value?.abortXhr?.();
}

onStartList.forEach((cb) => cb(wrapParams.value));

isPending.value = true;
Expand Down Expand Up @@ -158,14 +163,9 @@ const useAsync = <T,
() => wrapParams.value,
(v) => {
const vStr = JSON.stringify(v);
if (
!isPending.value
&& (
// fix if there is no change. Just undefined as value
(v === undefined && lastUnwrapParams.value === undefined)

// fix if there is no change. Just undefined as value
if ((v === undefined && lastUnwrapParams.value === undefined)
|| (_enabled.value && vStr !== JSON.stringify(lastUnwrapParams.value))
)
) {
_reload(v);
}
Expand Down

0 comments on commit 4081c6f

Please sign in to comment.