Skip to content

Commit e1647be

Browse files
committed
feat: use-request/useRequestProvider global option
1 parent 96ffec6 commit e1647be

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/hooks/src/useRequest/useRequestImplement.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ function useRequestImplement<TData, TParams extends any[]>(
1010
options: UseRequestOptions<TData, TParams, any> = {},
1111
plugins: UseRequestPlugin<TData, TParams>[] = [],
1212
) {
13-
// 全局注入的配置
13+
// global option
1414
const USEREQUEST_GLOBAL_OPTIONS = inject(USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY)
15-
// 读取配置
15+
// read option
1616
const { initialData = undefined, manual = false, ready = true, ...rest } = merge(
1717
USEREQUEST_GLOBAL_OPTIONS,
1818
options ?? {},
@@ -24,10 +24,10 @@ function useRequestImplement<TData, TParams extends any[]>(
2424
...rest,
2525
}
2626

27-
// 定义一个serviceRef
27+
// serviceRef store service
2828
const serviceRef = ref(service)
2929

30-
// 存储state的响应式对象
30+
// reactive
3131
const state = reactive<{
3232
data?: TData
3333
loading: boolean
@@ -52,7 +52,7 @@ function useRequestImplement<TData, TParams extends any[]>(
5252
}
5353

5454
const initState = plugins.map(p => p?.onInit?.(fetchOptions)).filter(Boolean)
55-
// fetch的实例化
55+
// Fetch Instance
5656
const fetchInstance = new Fetch<TData, TParams>(
5757
serviceRef,
5858
fetchOptions,
@@ -62,20 +62,20 @@ function useRequestImplement<TData, TParams extends any[]>(
6262

6363
fetchInstance.options = fetchOptions
6464

65-
// 运行插件
65+
// run plugins
6666
fetchInstance.pluginImpls = plugins.map(p => {
6767
return p(fetchInstance, fetchOptions)
6868
})
6969

70-
// manual控制是否自动发送请求
70+
// manual
7171
onMounted(() => {
7272
if (!manual) {
7373
const params = fetchInstance.state.params || options.defaultParams || []
7474
if (unref(ready)) fetchInstance.run(...(params as TParams))
7575
}
7676
})
7777

78-
// 组件卸载的时候取消请求
78+
// onUnmounted cancel request
7979
onUnmounted(() => {
8080
fetchInstance.cancel()
8181
})

0 commit comments

Comments
 (0)