diff --git a/.eslintrc.js b/.eslintrc.js index fe75bf1c08..0940038f38 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,7 +12,6 @@ module.exports = { '@typescript-eslint/ban-ts-ignore': 'off', '@typescript-eslint/no-object-literal-type-assertion': 'off', '@typescript-eslint/no-parameter-properties': 'off', - 'consistent-return': 'off', 'import/no-useless-path-segments': 'off', 'no-unused-expressions': 'off', 'react-hooks/rules-of-hooks': 'error', diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 4251b97960..48d0a91098 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -15,8 +15,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2.2.4 - with: - version: 7 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 233897b3c3..80f9072a8f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,8 +16,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2.2.4 - with: - version: 7 - name: Get pnpm store directory id: pnpm-cache diff --git a/LICENSE b/LICENSE index 35d401d35a..aebeda7fec 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 ahooks +Copyright (c) 2019-present ahooks Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 046735189d..220ae1d84c 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Thanks to all the contributors: ## 👥 Discuss - + [1]: https://www.npmjs.com/package/ahooks [2]: https://npmjs.org/package/ahooks diff --git a/README.zh-CN.md b/README.zh-CN.md index 8b23eac482..9c2363c4ed 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -79,7 +79,7 @@ $ pnpm start ## 👥 交流讨论 - + [1]: https://www.npmjs.com/package/ahooks [2]: https://npmjs.org/package/ahooks diff --git a/config/config.ts b/config/config.ts index b2cf6c1405..281a9c782d 100644 --- a/config/config.ts +++ b/config/config.ts @@ -180,20 +180,27 @@ export default { scripts: [ 'https://s4.cnzz.com/z_stat.php?id=1278992092&web_id=1278992092', ` - const insertVersion = function(){ + const insertVersion = function() { + const logo = document.querySelector('.__dumi-default-navbar-logo'); + if (!logo) return; const dom = document.createElement('span'); dom.id = 'logo-version'; dom.innerHTML = '${packages.version}'; - const logo = document.querySelector('.__dumi-default-navbar-logo'); - if(logo){ - logo.parentNode.insertBefore(dom, logo.nextSibling); - }else{ - setTimeout(()=>{ - insertVersion(); - }, 1000) + logo.parentNode.insertBefore(dom, logo.nextSibling); + }; + const observer = new MutationObserver((mutationsList, observer) => { + for (const mutation of mutationsList) { + if (mutation.type === 'childList') { + const logoVersion = document.querySelector('#logo-version'); + if (logoVersion) { + observer.disconnect(); + } else { + insertVersion(); + } + } } - } - insertVersion(); + }); + observer.observe(document.body, { childList: true, subtree: true }); `, ], }; diff --git a/docs/index.en-US.md b/docs/index.en-US.md index 1fd24da37c..3141b26eb5 100644 --- a/docs/index.en-US.md +++ b/docs/index.en-US.md @@ -73,7 +73,7 @@ Thanks to all the contributors: ## 👥 Discuss - + [1]: https://www.npmjs.com/package/ahooks [2]: https://npmjs.org/package/ahooks diff --git a/docs/index.zh-CN.md b/docs/index.zh-CN.md index 069fdb1f67..e55fd7ec3f 100644 --- a/docs/index.zh-CN.md +++ b/docs/index.zh-CN.md @@ -73,7 +73,7 @@ $ pnpm start ## 👥 交流讨论 - + [1]: https://www.npmjs.com/package/ahooks [2]: https://npmjs.org/package/ahooks diff --git a/package.json b/package.json index 3908351b00..566f5f7fe3 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "ahooks", "private": true, + "packageManager": "pnpm@7.33.6", "repository": { "type": "git", "url": "git+https://github.com/alibaba/hooks.git" diff --git a/packages/hooks/src/useExternal/demo/demo2.tsx b/packages/hooks/src/useExternal/demo/demo2.tsx index 785179ef71..5172b9cf1d 100644 --- a/packages/hooks/src/useExternal/demo/demo2.tsx +++ b/packages/hooks/src/useExternal/demo/demo2.tsx @@ -19,7 +19,7 @@ export default () => {
Status: {status}
-( +function useLockFn
(
fn: (...args: P) => Promise (fn: (...args: P) => Promise (fn: (...args: P) => Promise (
+function useLockFn (
fn: (...args: P) => Promise Username: {data} Username: {loading ? 'loading...' : data} Username: {data} Username: {loading ? 'loading...' : data}
@@ -41,7 +41,11 @@ useEffect(() => {
### Options
-| Property | Description | Type | Default |
-| ----------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | ------- |
-| refreshDeps | When the content of the array changes, trigger refresh. | `React.DependencyList` | `[]` |
-| refreshDepsAction | Customize the request behavior for dependency refresh, this parameter is called after initialization and dependencies changes. | `() => void` | - |
+| Property | Description | Type | Default |
+| ----------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------- | ------- |
+| refreshDeps | When the content of the array changes, trigger refresh. | `React.DependencyList` | `[]` |
+| refreshDepsAction | Customize the request behavior during dependency refresh; this parameter is invoked when dependencies change. | `() => void` | - |
+
+## Remark
+
+- If you set `options.manual = true`, both `refreshDeps` and `refreshDepsAction` are no longer effective, you need to trigger the request by `run/runAsync`.
diff --git a/packages/hooks/src/useRequest/doc/refreshDeps/refresyDeps.zh-CN.md b/packages/hooks/src/useRequest/doc/refreshDeps/refresyDeps.zh-CN.md
index e88e732e98..aff568171a 100644
--- a/packages/hooks/src/useRequest/doc/refreshDeps/refresyDeps.zh-CN.md
+++ b/packages/hooks/src/useRequest/doc/refreshDeps/refresyDeps.zh-CN.md
@@ -7,7 +7,7 @@ group:
# 依赖刷新
-通过设置 `options.refreshDeps`,在初始化和依赖变化时, `useRequest` 会自动调用 [refresh](https://ahooks.js.org/zh-CN/hooks/use-request/basic/#result) 方法,实现[刷新(重复上一次请求)](https://ahooks.js.org/zh-CN/hooks/use-request/basic/#刷新重复上一次请求)的效果。
+通过设置 `options.refreshDeps`,在依赖变化时, `useRequest` 会自动调用 [refresh](https://ahooks.js.org/zh-CN/hooks/use-request/basic/#result) 方法,实现[刷新(重复上一次请求)](https://ahooks.js.org/zh-CN/hooks/use-request/basic/#刷新重复上一次请求)的效果。
```tsx | pure
const [userId, setUserId] = useState('1');
@@ -29,7 +29,7 @@ useEffect(() => {
}, [userId]);
```
-### 刷新上一次请求
+### 重复上一次请求
@@ -41,7 +41,11 @@ useEffect(() => {
### Options
-| 参数 | 说明 | 类型 | 默认值 |
-| ----------------- | ------------------------------------------------------------------- | ------------ | ------ |
-| refreshDeps | 依赖数组,当数组内容变化后,发起请求。同 `useEffect` 的第二个参数。 | `any[]` | `[]` |
-| refreshDepsAction | 自定义依赖刷新时的请求行为,该参数会在初始化和依赖变化后被调用。 | `() => void` | - |
+| 参数 | 说明 | 类型 | 默认值 |
+| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------ |
+| refreshDeps | 依赖数组。当数组内容变化后[刷新(重复上一次请求)](https://ahooks.js.org/zh-CN/hooks/use-request/basic/#刷新重复上一次请求)。同 `useEffect` 的第二个参数。 | `any[]` | `[]` |
+| refreshDepsAction | 自定义依赖数组变化时的请求行为。 | `() => void` | - |
+
+## 备注
+
+- 如果设置 `options.manual = true`,则 `refreshDeps`, `refreshDepsAction` 都不再生效,需要通过 `run/runAsync` 手动触发请求。
diff --git a/packages/hooks/tsconfig.json b/packages/hooks/tsconfig.json
index 35cc81c1ab..04dc211e11 100644
--- a/packages/hooks/tsconfig.json
+++ b/packages/hooks/tsconfig.json
@@ -3,6 +3,8 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
- "composite": true
- }
+ "composite": true,
+ "declaration": true
+ },
+ "include": ["src"]
}
diff --git a/packages/use-url-state/tsconfig.json b/packages/use-url-state/tsconfig.json
index 3176325368..1dac9cf65d 100644
--- a/packages/use-url-state/tsconfig.json
+++ b/packages/use-url-state/tsconfig.json
@@ -2,5 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src"
- }
+ },
+ "include": ["src"]
}
diff --git a/tsconfig.json b/tsconfig.json
index d8c6842baf..32aff75270 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -9,8 +9,6 @@
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
- "ahooks": ["./packages/hooks/src/index.ts"],
- "ahooks/lib/*": ["./packages/hooks/src/*"],
"@ahooksjs/use-url-state": ["./packages/use-url-state/src/index.ts"]
},
"allowSyntheticDefaultImports": true,