Skip to content

Commit 5dfad95

Browse files
authored
feat: optimized useRequest refreshDeps type && docs opt
feat: optimized useRequest refreshDeps type && docs opt
2 parents e710d69 + b9b92d4 commit 5dfad95

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

packages/hooks/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import useFormatResult from './useFormatResult'
1717
import useFetchs from './useFetchs'
1818
import useFullscreen from './useFullscreen'
1919
import useHover from './useHover'
20-
// import usePreview from './usePreview'
2120
import usePrevious from './usePrevious'
2221
import useInterval from './useInterval'
2322
import useInfiniteScroll from './useInfiniteScroll'
@@ -82,7 +81,6 @@ export {
8281
useMedia,
8382
useMouse,
8483
useNetwork,
85-
// usePreview,
8684
usePrevious,
8785
useSessionStorageState,
8886
useSet,

packages/hooks/src/useDarkMode/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function useDarkMode(): [ComputedRef<boolean>, (value?: unknown)
1616
})
1717

1818
watchEffect(() => {
19-
const className = 'dark-mode'
19+
const className = '[vue-hooks-plus]-dark-mode'
2020
const element = window.document.body
2121
if (enabled.value) {
2222
element.classList.add(className)

packages/hooks/src/useRequest/docs/refreshDeps/demo/demo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<vhp-button type="button" @click="count++">count is {{ count }}</vhp-button>
55
<div style="opacity: 0.6;"> count !==0 and count !==5 ready is true </div>
66
</div>
7-
<br>
7+
<br />
88
<vhp-button @click="() => (id = 1)">Change ID = 1</vhp-button>
99
<vhp-button @click="() => (id = 2)" style="margin-left: 16px;">Change ID = 2</vhp-button>
1010
<vhp-button @click="() => (store.id = 1)" style="margin-left: 16px;">

packages/hooks/src/useRequest/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import useRequest from './useRequest'
22
import useRequestProvider from './useRequestProvider'
3-
// import createUseRequest from './createUseRequest'
43
import { clearCache as clearUseRequestCache } from './utils/cache'
54

65
import useRequestDevToolsPlugin from './devtools'

packages/hooks/src/useRequest/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Ref, WatchSource } from 'vue'
1+
import { Ref, watch } from 'vue'
22
import { CachedData } from './utils/cache'
33
import UseRequestFetch from './Fetch'
44

@@ -97,7 +97,7 @@ export interface UseRequestBasicOptions<TData, TParams extends unknown[]> {
9797
/**
9898
* Dependent on responsive objects, and the `watch` incoming listener object usage for `vue`.
9999
*/
100-
refreshDeps?: WatchSource[] | boolean
100+
refreshDeps?: Parameters<typeof watch>[0][] | boolean
101101
refreshDepsAction?: () => void
102102

103103
/**
@@ -106,10 +106,13 @@ export interface UseRequestBasicOptions<TData, TParams extends unknown[]> {
106106
*/
107107
loadingDelay?: number | Ref<number>
108108

109+
/**
110+
* open vue devtools,devKey must existence and uniqueness.
111+
*/
109112
devKey?: string
110113

111114
/**
112-
* Format the request results, which recommend to use `useFormatResult`
115+
* Format the request results, which recommend to use `useFormatResult`.
113116
* @param data TData
114117
* @returns unknown need cover TData
115118
*/

packages/hooks/src/useRequest/useRequestImplement.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, reactive, toRefs, onUnmounted, inject, UnwrapRef, watchEffect, computed, isRef, onMounted, unref } from 'vue'
1+
import { ref, reactive, toRefs, onUnmounted, inject, UnwrapRef, watchEffect, computed, isRef, unref } from 'vue'
22

33
import Fetch from './Fetch'
44
import { USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY } from './config'
@@ -93,12 +93,10 @@ function useRequestImplement<TData, TParams extends any[]>(
9393
})
9494

9595
// manual
96-
onMounted(() => {
97-
if (!manual && fetchInstance.options.refreshDeps !== true) {
98-
const params = fetchInstance.state.params || options.defaultParams || []
99-
if (unref(ready)) fetchInstance.run(...(params as TParams))
100-
}
101-
})
96+
if (!manual && fetchInstance.options.refreshDeps !== true) {
97+
const params = fetchInstance.state.params || options.defaultParams || []
98+
if (unref(ready)) fetchInstance.run(...(params as TParams))
99+
}
102100

103101
// onUnmounted cancel request
104102
onUnmounted(() => {

0 commit comments

Comments
 (0)