Skip to content

Commit 89f82eb

Browse files
committed
style: 🎨 notes & type prefix
1 parent 3585a08 commit 89f82eb

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

packages/hooks/src/useRequest/docs/pluginDoc/index.en-US.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ Advocate for a plugin initiated with `use`, named after `Plugin` ending, `useXxx
2121
## Convened Typescript type definition
2222

2323
```typescript
24-
const useXxxxPlugin: Plugin<TData, TParams, PluginOption> = Fn(fetchInstance, options)
24+
const useXxxxPlugin: UseRequestPlugin<TData, TParams, UseRequestPluginOption> = Fn(
25+
fetchInstance,
26+
options,
27+
)
2528
```
2629

2730
`useRequest` will export a plugin type as a modification, the generic corresponds to `useRequest`'s `data`, `params`, `PluginOption`
@@ -31,21 +34,21 @@ const useXxxxPlugin: Plugin<TData, TParams, PluginOption> = Fn(fetchInstance, op
3134
Corresponding to the 👆 's `Fn` function, the function's first parameter is the `fetchInstance` instance, and you can use all the methods carried on this instance.
3235

3336
```typescript
34-
cancel: Fetch < TData, TParams > ['cancel']
35-
refresh: Fetch < TData, TParams > ['refresh']
36-
refreshAsync: Fetch < TData, TParams > ['refreshAsync']
37-
run: Fetch < TData, TParams > ['run']
38-
runAsync: Fetch < TData, TParams > ['runAsync']
39-
mutate: Fetch < TData, TParams > ['mutate']
37+
cancel: UseRequestFetch < TData, TParams > ['cancel']
38+
refresh: UseRequestFetch < TData, TParams > ['refresh']
39+
refreshAsync: UseRequestFetch < TData, TParams > ['refreshAsync']
40+
run: UseRequestFetch < TData, TParams > ['run']
41+
runAsync: UseRequestFetch < TData, TParams > ['runAsync']
42+
mutate: UseRequestFetch < TData, TParams > ['mutate']
4043
```
4144

4245
Corresponding to the 👆 `Fn` function, the function the second parameter is the `options` configuration, and you can use all the configuration items carried by the `useRequest`, including those defined by your plugin.
4346

4447
```typescript
4548

46-
type Options
49+
type UseRequestOptions
4750
&
48-
type PlginOptions
51+
type UseRequestPlginOptions
4952

5053
```
5154

@@ -54,18 +57,18 @@ Corresponding to the 👆 `Fn` function, the function the second parameter is th
5457
As a function of this, it is required to return the plugin running results in the plugin cycle, such as executing a segment of logic in `onSuccess` and a segment of error processing in `onError`.
5558

5659
```typescript
57-
interface PluginReturn<TData, TParams extends any[]> {
60+
interface UseRequestPluginReturn<TData, TParams extends any[]> {
5861
onBefore?: (
5962
params: TParams,
6063
) =>
6164
| ({
6265
stopNow?: boolean
6366
returnNow?: boolean
64-
} & Partial<FetchState<TData, TParams>>)
67+
} & Partial<UseRequestFetchState<TData, TParams>>)
6568
| void
6669

6770
onRequest?: (
68-
service: Service<TData, TParams>,
71+
service: UseRequestService<TData, TParams>,
6972
params: TParams,
7073
) => {
7174
servicePromise?: Promise<TData>
@@ -95,7 +98,7 @@ Need to setup `data`, `params`, `loading`, `error` Change requires use using the
9598
Return the results after the request data has processed the data, call `setData` to reset the value.
9699

97100
```typescript
98-
const useFormatterPlugin: Plugin<
101+
const useFormatterPlugin: UseRequestPlugin<
99102
{
100103
name: string
101104
age: number
@@ -128,6 +131,6 @@ const { data } = useRequest(
128131

129132
## Options
130133

131-
| Property | Description | Type | Default |
132-
| -------- | ------------- | ----------------------------------------- | ------- |
133-
| Plugin | Custom plugin | `(fetchInstance, option) => PluginReturn` | - |
134+
| Property | Description | Type | Default |
135+
| -------- | ------------- | --------------------------------------------------- | ------- |
136+
| Plugin | Custom plugin | `(fetchInstance, option) => UseRequestPluginReturn` | - |

packages/hooks/src/useRequest/docs/pluginDoc/index.zh-CN.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ source:
2424
## 约定式 Typescript 类型定义
2525

2626
```typescript
27-
const useXxxxPlugin: Plugin<TData, TParams, PluginOption> = Fn(fetchInstance, options)
27+
const useXxxxPlugin: UseRequestPlugin<TData, TParams, UseRequestPluginOption> = Fn(
28+
fetchInstance,
29+
options,
30+
)
2831
```
2932

3033
`useRequest` 会导出一个插件类型作为修饰,泛型对应 `useRequest``data``params``PluginOption`
@@ -34,21 +37,21 @@ const useXxxxPlugin: Plugin<TData, TParams, PluginOption> = Fn(fetchInstance, op
3437
对应 👆 的 `Fn` 函数,函数第一个参数为 `fetchInstance` 实例,你可以使用这个实例上携带的所有方法。
3538

3639
```typescript
37-
cancel: Fetch < TData, TParams > ['cancel']
38-
refresh: Fetch < TData, TParams > ['refresh']
39-
refreshAsync: Fetch < TData, TParams > ['refreshAsync']
40-
run: Fetch < TData, TParams > ['run']
41-
runAsync: Fetch < TData, TParams > ['runAsync']
42-
mutate: Fetch < TData, TParams > ['mutate']
40+
cancel: UseRequestFetch < TData, TParams > ['cancel']
41+
refresh: UseRequestFetch < TData, TParams > ['refresh']
42+
refreshAsync: UseRequestFetch < TData, TParams > ['refreshAsync']
43+
run: UseRequestFetch < TData, TParams > ['run']
44+
runAsync: UseRequestFetch < TData, TParams > ['runAsync']
45+
mutate: UseRequestFetch < TData, TParams > ['mutate']
4346
```
4447

4548
对应 👆 的 `Fn` 函数,函数第二个参数为 `options` 配置,你可以使用`useRequest`携带的所有配置项,包括你插件定义的配置项。
4649

4750
```typescript
4851

49-
type Options
52+
type UseRequestOptions
5053
&
51-
type PlginOptions
54+
type UseRequestPlginOptions
5255

5356
```
5457

@@ -57,18 +60,18 @@ mutate: Fetch < TData, TParams > ['mutate']
5760
插件作为一个函数,这里需要约定式的在插件周期中返回插件运行结果,如在 `onSuccess` 执行某段逻辑,在 `onError` 执行某段错误处理的逻辑。
5861

5962
```typescript
60-
interface PluginReturn<TData, TParams extends any[]> {
63+
interface UseRequestPluginReturn<TData, TParams extends any[]> {
6164
onBefore?: (
6265
params: TParams,
6366
) =>
6467
| ({
6568
stopNow?: boolean
6669
returnNow?: boolean
67-
} & Partial<FetchState<TData, TParams>>)
70+
} & Partial<UseRequestFetchState<TData, TParams>>)
6871
| void
6972

7073
onRequest?: (
71-
service: Service<TData, TParams>,
74+
service: UseRequestService<TData, TParams>,
7275
params: TParams,
7376
) => {
7477
servicePromise?: Promise<TData>
@@ -98,7 +101,7 @@ interface PluginReturn<TData, TParams extends any[]> {
98101
在请求数据完成后将 外部传入的 `formatter` 处理完数据后将结果返回,调用 `setData` 重新设置值。
99102

100103
```typescript
101-
const useFormatterPlugin: Plugin<
104+
const useFormatterPlugin: UseRequestPlugin<
102105
{
103106
name: string
104107
age: number
@@ -131,6 +134,6 @@ const { data } = useRequest(
131134

132135
## Options
133136

134-
| 参数 | 说明 | 类型 | 默认值 |
135-
| ------ | ---------- | ----------------------------------------- | ------ |
136-
| Plugin | 自定义插件 | `(fetchInstance, option) => PluginReturn` | - |
137+
| 参数 | 说明 | 类型 | 默认值 |
138+
| ------ | ---------- | --------------------------------------------------- | ------ |
139+
| Plugin | 自定义插件 | `(fetchInstance, option) => UseRequestPluginReturn` | - |

0 commit comments

Comments
 (0)