Skip to content

Commit 3e3cc12

Browse files
committed
style: use-request image code line
1 parent b3ec84f commit 3e3cc12

File tree

3 files changed

+6
-61
lines changed

3 files changed

+6
-61
lines changed

packages/use-request/src/createUseRequest.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/use-request/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import useRequest from './useRequest'
22
import useRequestProvider from './useRequestProvider'
3-
import createUseRequest from './createUseRequest'
43
import { clearCache as clearUseRequestCache } from './utils/cache'
54

6-
export { clearUseRequestCache, createUseRequest, useRequestProvider }
5+
export { clearUseRequestCache, useRequestProvider }
76

87
export default useRequest

packages/use-request/src/useRequestImplement.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
import {
2-
ref,
3-
reactive,
4-
toRefs,
5-
onUnmounted,
6-
inject,
7-
UnwrapRef,
8-
watchEffect,
9-
computed,
10-
isRef,
11-
onMounted,
12-
unref,
13-
} from 'vue'
1+
import { ref, reactive, toRefs, onUnmounted, inject, UnwrapRef, watchEffect, computed, isRef, onMounted, unref } from 'vue'
142

153
import Fetch from './Fetch'
164
import { USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY } from './config'
@@ -29,18 +17,11 @@ function isUseRequestFetchState<TData, TParams extends any[]>(
2917
return keys.filter(i => ['data', 'loading', 'params', 'error'].includes(i)).length === 4
3018
}
3119

32-
// function isUseRequestFetchStateKey<TData, TParams extends any[]>(
33-
// field: string,
34-
// state: unknown,
35-
// ): state is UseRequestFetchState<TData, TParams>[keyof UseRequestFetchState<TData, TParams>] {
36-
// return Boolean(['data', 'loading', 'params', 'error'].find(i => i === field))
37-
// }
38-
3920
function useRequestImplement<TData, TParams extends any[]>(
4021
service: UseRequestService<TData, TParams>,
4122
options: UseRequestOptions<TData, TParams, any> = {},
4223
plugins: UseRequestPlugin<TData, TParams>[] = [],
43-
): useRequestResult<TData, TParams> {
24+
) {
4425
// global option
4526
const USEREQUEST_GLOBAL_OPTIONS = inject<Record<string, any>>(
4627
USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY,
@@ -69,11 +50,8 @@ function useRequestImplement<TData, TParams extends any[]>(
6950
error: undefined,
7051
})
7152

72-
const setState = (currentState: unknown, field?: keyof typeof state): void => {
53+
const setState = (currentState: unknown, field?: keyof typeof state) => {
7354
if (field) {
74-
// if (isUseRequestFetchStateKey<UnwrapRef<TData>, UnwrapRef<TParams>>(field, currentState)) {
75-
// state[field] = currentState as any
76-
// }
7755
state[field] = currentState as any
7856
} else {
7957
if (isUseRequestFetchState<UnwrapRef<TData>, UnwrapRef<TParams>>(currentState)) {
@@ -101,20 +79,12 @@ function useRequestImplement<TData, TParams extends any[]>(
10179
return p(fetchInstance, fetchOptions)
10280
})
10381

104-
const readyComputed = computed(() => (isRef(ready) ? ready.value : ready))
105-
106-
// const isMount = ref(false)
82+
const readyComputed = computed(() => isRef(ready) ? ready.value : ready)
10783

10884
watchEffect(() => {
10985
if (!manual) {
11086
const params = fetchInstance.state.params || options.defaultParams || []
111-
// if (readyComputed.value && !isMount.value) {
112-
// fetchInstance.run(...(params as TParams))
113-
// // 模拟首次mount
114-
// isMount.value = true
115-
116-
// }
117-
// 自动收集依赖
87+
// auto collect
11888
if (readyComputed.value && fetchInstance.options.refreshDeps === true && !!serviceRef.value) {
11989
fetchInstance.run(...(params as TParams))
12090
}

0 commit comments

Comments
 (0)