Skip to content

Commit c82f6a5

Browse files
committed
Merge branch 'feature/[email protected]'
2 parents 489a264 + 8d2f41c commit c82f6a5

File tree

7 files changed

+81
-34
lines changed

7 files changed

+81
-34
lines changed

docs/tutorial/03-client/01-strategy/04-use-pagination.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,9 @@ When you do not want to update the list items locally after the data operation,
614614
* If no page number is passed in, the current page will be refreshed
615615
* If a list item is passed in, the page where the list item is located will be refreshed
616616
* @param pageOrItemPage Refreshed page number or list item
617+
* @returns [v3.1.0+]an promise that contains response data
617618
*/
618-
declare function refresh(pageOrItemPage?: number | LD[number]): void;
619+
declare function refresh(pageOrItemPage?: number | LD[number]): Promise<AG['Responded']>;
619620
```
620621

621622
In append mode, you can specify the parameter of `refresh` as a list item. When the same reference of this list item is found, the data of the page number where this list item is located will be refreshed.
@@ -638,8 +639,9 @@ It will clear all caches and reload the first page.
638639
```typescript
639640
/**
640641
* Reload the list from the first page and clear the cache
642+
* @returns [v3.1.0+]an promise instance that indicate if the reset is successful
641643
*/
642-
declare function reload(): void;
644+
declare function reload(): Primise<void>;
643645
```
644646

645647
## Compatible with `updateState`
@@ -705,14 +707,14 @@ Inherit all responsive data from [**useWatcher**](/api/core-hooks#usewatcher).
705707

706708
Inherit all action functions of [**useWatcher**](/api/core-hooks#usewatcher).
707709

708-
| name | description | function parameters | return value | version |
709-
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------- |
710-
| refresh | Refresh the data of the specified page number, this function will ignore the forced sending request of the cache, in the append mode, the list item can be passed in to indicate the page number where the list item is refreshed | pageOrItemPage: Refreshed page number or list item | - | - |
711-
| insert | Insert a piece of data. If no index is passed in, it will be inserted at the front by default. If a list item is passed in, it will be inserted after the list item. If the list item is not in the list data, an error will be thrown | 1. item: insert item<br/>2. indexOrItem: insert position (index) or list item, default is 0 | - | - |
712-
| remove | Remove a piece of data. When a number is passed in, it means the removed index. When the position is passed in a list item, the list item will be removed. If the list item is not in the list data, an error will be thrown | position : remove position (index) or list item | - | - |
713-
| replace | Replace a piece of data. When the second parameter is passed in a number, it means the replacement index. A negative number means counting from the end. When the position passed in is a list item, the list item will be replaced. If the list item is not in the list data An error will be thrown | 1. item: replacement item<br/>2. position: replacement position (index) or list item, when a negative number is passed in, it means counting from the end | - | - |
714-
| reload | Clear the data and re-request the first page of data | - | - | - |
715-
| update | Update state data, same as alova's use hook, but update list data when updating data field | newFrontStates: new state data object | - | - |
710+
| name | description | function parameters | return value | version |
711+
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ------- |
712+
| refresh | Refresh the data of the specified page number, this function will ignore the forced sending request of the cache, in the append mode, the list item can be passed in to indicate the page number where the list item is refreshed | pageOrItemPage: Refreshed page number or list item | Promise\<AG\['Responded'\]\> | v3.1.0+ |
713+
| insert | Insert a piece of data. If no index is passed in, it will be inserted at the front by default. If a list item is passed in, it will be inserted after the list item. If the list item is not in the list data, an error will be thrown | 1. item: insert item<br/>2. indexOrItem: insert position (index) or list item, default is 0 | - | - |
714+
| remove | Remove a piece of data. When a number is passed in, it means the removed index. When the position is passed in a list item, the list item will be removed. If the list item is not in the list data, an error will be thrown | position : remove position (index) or list item | - | - |
715+
| replace | Replace a piece of data. When the second parameter is passed in a number, it means the replacement index. A negative number means counting from the end. When the position passed in is a list item, the list item will be replaced. If the list item is not in the list data An error will be thrown | 1. item: replacement item<br/>2. position: replacement position (index) or list item, when a negative number is passed in, it means counting from the end | - | - |
716+
| reload | Clear the data and re-request the first page of data | - | Promise\<void\> | v3.1.0+ |
717+
| update | Update state data, same as alova's use hook, but update list data when updating data field | newFrontStates: new state data object | - | - |
716718

717719
### Event
718720

docs/tutorial/03-client/01-strategy/08-action-delegation-middleware.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { actionDelegationMiddleware } from 'alova/client';
3939

4040
useRequest(queryTodo, {
4141
//...
42-
middleware: actionDelegationMiddleware('actionName')
42+
middleware: actionDelegationMiddleware('testAction')
4343
});
4444
```
4545

@@ -48,7 +48,7 @@ In any component (such as component B), pass in the specified delegate name thro
4848
```javascript title=Component B
4949
import { accessAction } from 'alova/client';
5050

51-
accessAction('actionName', delegatedActions => {
51+
accessAction('testAction', delegatedActions => {
5252
// Call the send function in component A
5353
delegatedActions.send();
5454

@@ -59,11 +59,26 @@ accessAction('actionName', delegatedActions => {
5959

6060
:::info note
6161

62-
1. All use hooks in alova support action function delegation, but the functions delegated by different use hooks are different.
63-
2. When using `actionDelegationMiddleware`, the delegate name can be passed in strings, numbers, and symbol values.
62+
1. The use hook that only makes request will have its actions delegated
63+
2. All use hooks in alova support action function delegation, but the functions delegated by different use hooks are different.
64+
3. When using `actionDelegationMiddleware`, the delegate name can be passed in strings, numbers, and symbol values.
6465

6566
:::
6667

68+
### Silently access actions
69+
70+
By default, an error will be throwed when the action delegate of `testAction` is not found, which can help you locate problems, but if you are not sure whether the target actions are delegated when calling `accessAction`, you can prevent the error by passing the third parameter `true`.
71+
72+
```javascript
73+
accessAction(
74+
'testAction',
75+
delegatedActions => {
76+
delegatedActions.send();
77+
},
78+
true
79+
);
80+
```
81+
6782
### Batch trigger action function
6883

6984
In the above example, we use `accessAction` to trigger the action function of a use hook, but in fact, delegates with the same name will not override each other, but will be stored in a group, and we can use this name to trigger them at the same time The delegated function.
@@ -73,7 +88,7 @@ import { actionDelegationMiddleware } from 'alova/client';
7388

7489
useRequest(queryTodo, {
7590
//...
76-
middleware: actionDelegationMiddleware('actionName1')
91+
middleware: actionDelegationMiddleware('testAction1')
7792
});
7893
```
7994

@@ -82,15 +97,15 @@ import { actionDelegationMiddleware } from 'alova/client';
8297

8398
useRequest(queryTodo, {
8499
//...
85-
middleware: actionDelegationMiddleware('actionName1')
100+
middleware: actionDelegationMiddleware('testAction1')
86101
});
87102
```
88103

89104
```javascript title=Component E
90105
import { accessAction } from 'alova/client';
91106

92107
// Because the delegate hooks of component C and component D will be matched, the callback function will be executed twice
93-
accessAction('actionName1', delegatedActions => {
108+
accessAction('testAction1', delegatedActions => {
94109
// Call the send function in component C and component D
95110
delegatedActions.send();
96111

i18n/zh-CN/docusaurus-plugin-content-docs/current/tutorial/03-client/01-strategy/04-use-pagination.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,9 @@ declare function replace(
614614
* 如果未传入页码则会刷新当前页
615615
* 如果传入一个列表项,将会刷新此列表项所在页
616616
* @param pageOrItemPage 刷新的页码或列表项
617+
* @returns [v3.1.0+]包含响应数据的promise
617618
*/
618-
declare function refresh(pageOrItemPage?: number | LD[number]): void;
619+
declare function refresh(pageOrItemPage?: number | LD[number]): Promise<AG['Responded']>;
619620
```
620621

621622
在 append 模式下,你可以将`refresh`的参数指定为列表项,当查找到这个列表项的相同引用时,刷新此列表项所在页数的数据。
@@ -638,8 +639,9 @@ update({
638639
```typescript
639640
/**
640641
* 从第一页开始重新加载列表,并清空缓存
642+
* @returns [v3.1.0+]promise实例,表示是否重置成功
641643
*/
642-
declare function reload(): void;
644+
declare function reload(): Promise<void>;
643645
```
644646

645647
## `updateState`兼容使用
@@ -705,14 +707,14 @@ updateState<Item[]>(listMethod, {
705707

706708
继承[**useWatcher**](/api/core-hooks#usewatcher)所有操作函数。
707709

708-
| 名称 | 描述 | 函数参数 | 返回值 | 版本 |
709-
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- | ------ | ---- |
710-
| refresh | 刷新指定页码数据,此函数将忽略缓存强制发送请求,append 模式下可传入列表项表示刷新此列表项所在的页数 | pageOrItemPage: 刷新的页码或列表项 | - | - |
711-
| insert | 插入一条数据,如果未传入 index,将默认插入到最前面,如果传入一个列表项,将插入到这个列表项的后面,如果列表项未在列表数据中将会抛出错误 | 1. item: 插入项<br/>2. indexOrItem: 插入位置(索引)或列表项,默认为 0 | - | - |
712-
| remove | 移除一条数据,当传入数字时表示移除的索引,当 position 传入的是列表项,将移除此列表项,如果列表项未在列表数据中将会抛出错误 | position: 移除位置(索引)或列表项 | - | - |
713-
| replace | 替换一条数据,当第二个参数传入数字时表示替换索引,负数表示从末尾算起,当 position 传入的是列表项,将替换此列表项,如果列表项未在列表数据中将会抛出错误 | 1. item: 替换项<br/>2. position: 替换位置(索引)或列表项,传入负数时表示从末尾开始算起 | - | - |
714-
| reload | 清空数据,并重新请求第一页数据 | - | - | - |
715-
| update | 更新状态数据,与 alova 的 use hook 用法相同,但在更新 data 字段时是更新列表数据 | newFrontStates:新的状态数据对象 | - | - |
710+
| 名称 | 描述 | 函数参数 | 返回值 | 版本 |
711+
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- | ---------------------------- | ------- |
712+
| refresh | 刷新指定页码数据,此函数将忽略缓存强制发送请求,append 模式下可传入列表项表示刷新此列表项所在的页数 | pageOrItemPage: 刷新的页码或列表项 | Promise\<AG\['Responded'\]\> | v3.1.0+ |
713+
| insert | 插入一条数据,如果未传入 index,将默认插入到最前面,如果传入一个列表项,将插入到这个列表项的后面,如果列表项未在列表数据中将会抛出错误 | 1. item: 插入项<br/>2. indexOrItem: 插入位置(索引)或列表项,默认为 0 | - | - |
714+
| remove | 移除一条数据,当传入数字时表示移除的索引,当 position 传入的是列表项,将移除此列表项,如果列表项未在列表数据中将会抛出错误 | position: 移除位置(索引)或列表项 | - | - |
715+
| replace | 替换一条数据,当第二个参数传入数字时表示替换索引,负数表示从末尾算起,当 position 传入的是列表项,将替换此列表项,如果列表项未在列表数据中将会抛出错误 | 1. item: 替换项<br/>2. position: 替换位置(索引)或列表项,传入负数时表示从末尾开始算起 | - | - |
716+
| reload | 清空数据,并重新请求第一页数据 | - | Promise\<void\> | v3.1.0+ |
717+
| update | 更新状态数据,与 alova 的 use hook 用法相同,但在更新 data 字段时是更新列表数据 | newFrontStates:新的状态数据对象 | - | - |
716718

717719
### 事件
718720

0 commit comments

Comments
 (0)