Skip to content

Commit 849caed

Browse files
committed
docs: fix format in max/data-flow.en-US.md
1 parent 4957ad2 commit 849caed

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

docs/docs/docs/max/data-flow.en-US.md

+34-35
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
---
22
order: 5
33
toc: content
4-
translated_at: '2024-03-17T09:24:49.645Z'
4+
translated_at: '2024-03-18T00:49:20.502Z'
55
---
66

7-
```markdown
87
# Data Stream
98

10-
`@umi/max` has a built-in **data stream management** [plugin](https://github.com/umijs/umi/blob/master/packages/plugins/src/model.ts), which is a lightweight data management solution based on the `hooks` paradigm. It allows managing global shared data in Umi projects.
9+
`@umi/max` has a built-in **data flow management** [plugin](https://github.com/umijs/umi/blob/master/packages/plugins/src/model.ts), which is a lightweight data management solution based on the `hooks` paradigm. It can be used to manage global shared data in Umi projects.
1110

1211
## Getting Started
1312

1413
### Creating a Model
1514

16-
The data stream management plugin adopts a conventional directory structure. We agree that you can include Model files in the `src/models`, `src/pages/xxxx/models/` directory, and `src/pages/xxxx/model.{js,jsx,ts,tsx}` files.
17-
Model files can use `.(tsx|ts|jsx|js)` four suffix formats, the **namespace** generation rule is as follows.
15+
The data flow management plugin adopts a conventional directory structure. We agree that Model files can be introduced in the `src/models`, `src/pages/xxxx/models/` directories, and in `src/pages/xxxx/model.{js,jsx,ts,tsx}` files.
16+
Model files can have one of four suffix formats: `.(tsx|ts|jsx|js)`. The **namespace** generation rule is as follows.
1817

19-
| Path | Namespace | Explanation |
18+
| Path | Namespace | Description |
2019
| :--- |:--- | :--- |
21-
| `src/models/count.ts` | `count` | `src/models` directory does not support nested directory definition model |
20+
| `src/models/count.ts` | `count` | Defining model in `src/models` directory does not support directory nesting |
2221
| `src/pages/pageA/model.ts` | `pageA.model` | |
2322
| `src/pages/pageB/models/product.ts` | `pageB.product` | |
24-
| `src/pages/pageB/models/fruit/apple.ts` | `pageB.fruit.apple` | `pages/xxx/models` under model definition supports nested definition |
23+
| `src/pages/pageB/models/fruit/apple.ts` | `pageB.fruit.apple` | Definition in `pages/xxx/models` supports nested models |
2524

26-
A Model is essentially a custom `hooks` that doesn't involve any "black magic" that users need to worry about.
25+
A Model is essentially a custom `hook` with no "black magic" for the user to worry about.
2726

28-
When you need to get the global data in the Model, you can call its namespace. For example, for the Model file `userModel.ts`, its namespace is `userModel`.
27+
When we need to access the global data in the Model, we can call the namespace directly. For example, for a Model file `userModel.ts`, its namespace is `userModel`.
2928

3029
Write a function with a default export:
3130

@@ -40,13 +39,13 @@ export default function Page() {
4039
};
4140
```
4241

43-
This is a Model. The plugin's job is to turn the state or data within it into **global data**, so when different components use this Model, they get the same set of state or data.
42+
This is a Model. What the plugin does is turn the state or data in it into **global data**, providing the same state or data to different components using that Model.
4443

4544
:::info{title=💡}
46-
The Model file needs to default export a function, which defines a `hook`. Files that do not comply with this specification will be filtered out and cannot be called by namespace.
45+
The Model file needs to export a function by default, which defines a `hook`. Files that do not conform to this standard will be filtered out and cannot be called by namespace.
4746
:::
4847

49-
The Model can use other `hooks`, taking a counter as an example:
48+
It's allowed to use other `hooks` in a Model. Take a counter as an example:
5049

5150
```ts
5251
// src/models/counterModel.ts
@@ -62,7 +61,7 @@ export default function Page() {
6261
};
6362
```
6463

65-
In project practice, we usually need to request backend interfaces to obtain the required data. Now let's extend the previous example of getting user information:
64+
In real-world projects, we usually need to request backend interfaces to obtain the data we need. Now let's expand the previous example of fetching user information:
6665

6766
```ts
6867
// src/models/userModel.ts
@@ -110,9 +109,9 @@ export default function Page() {
110109
};
111110
```
112111

113-
### Using Model
112+
### Using a Model
114113

115-
Now, if you want to use a global Model in a specific component. Taking user information as an example, just call the `useModel` hook function:
114+
Now, you want to use a global Model in a certain component. Taking the user information as an example, you only need to call the `useModel` hook function:
116115

117116
```tsx
118117
// src/components/Username/index.tsx
@@ -127,17 +126,17 @@ export default function Page() {
127126
}
128127
```
129128

130-
In this case, the `useModel()` method's parameter is the Model's **namespace**.
129+
The `useModel()` method's argument is the Model's **namespace**.
131130

132131
:::info{title=💡}
133-
If you use VSCode as the IDE for developing Umi projects, it is recommended to use in conjunction with the [@umijs/plugin-model](https://marketplace.visualstudio.com/items?itemName=litiany4.umijs-plugin-model) plugin. It allows you to quickly jump to the file that defines the Model:
132+
If you use VSCode as the IDE for developing Umi projects, it's recommended to use it in conjunction with the [@umijs/plugin-model](https://marketplace.visualstudio.com/items?itemName=litiany4.umijs-plugin-model) plugin. It allows you to quickly jump to the file that defines the Model:
134133

135-
![vscode - @umijs/plugin-model plugin demonstration](https://gw.alipayobjects.com/zos/antfincdn/WcVbbF6KG2/1577073518336-afe6f03d-f817-491a-848a-5feeb4ecd72b.gif)
134+
![vscode - @umijs/plugin-model plugin demo](https://gw.alipayobjects.com/zos/antfincdn/WcVbbF6KG2/1577073518336-afe6f03d-f817-491a-848a-5feeb4ecd72b.gif)
136135
:::
137136

138137
## Performance Optimization
139138

140-
The `useModel()` method can accept an optional second parameter. When the component only needs to use part of the Model's parameters and is not interested in the changes of other parameters, a function can be passed in for filtering. Taking the operation buttons of the counter as an example:
139+
The `useModel()` method can accept an optional second parameter. When a component only needs to use part of the Model and is not interested in changes to other parameters, you can pass in a function to filter. Take the operation button for the counter as an example:
141140

142141
```tsx
143142
// src/components/CounterActions/index.tsx
@@ -158,17 +157,17 @@ export default function Page() {
158157
};
159158
```
160159

161-
The above component is not concerned with the `counter` value in the counter Model, only needing to use the `increment()` and `decrement()` methods provided by the Model. Thus, we passed in a function as the second parameter of the `useModel()` method, whose return value will serve as the `useModel()` method's return value.
160+
The above component is not interested in the `counter` value in the counter Model, and only needs to use the `increment()` and `decrement()` methods provided by the Model. Therefore, we passed in a function as the second argument for the `useModel()` method, and its return value will be used as the return value of the `useModel()` method.
162161

163-
This way, we filter out the frequently changing `counter` value, avoiding performance loss caused by repeated rendering of the component.
162+
This way, we have filtered out the frequently changing `counter` value, avoiding the performance loss caused by the component's repetitive rendering.
164163

165164
## Global Initial State
166165

167-
`@umi/max` has a built-in **global initial state management** [plugin](https://github.com/umijs/umi/blob/master/packages/plugins/src/initial-state.ts), allowing you to quickly build and obtain the global initial state of Umi projects within components.
166+
`@umi/max` has a built-in **global initial state management** [plugin](https://github.com/umijs/umi/blob/master/packages/plugins/src/initial-state.ts), which allows you to quickly build and access the global initial state of Umi projects within components.
168167

169168
The global initial state is a special Model.
170169

171-
The global initial state is created at the very beginning of the entire Umi project. Write the `getInitialState()` export method in `src/app.ts`, whose return value will become the global initial state. For example:
170+
The global initial state is created at the very beginning of the entire Umi project. Write the export method `getInitialState()` in `src/app.ts`, and its return value will become the global initial state. For example:
172171

173172
```ts
174173
// src/app.ts
@@ -180,7 +179,7 @@ export async function getInitialState() {
180179
}
181180
```
182181

183-
Now, various plugins and components you define can directly obtain this global initial state through `useModel('@@initialState')`, as shown below:
182+
Now, various plugins and your defined components can directly access this global initial state through `useModel('@@initialState')` as shown below:
184183

185184
```tsx
186185
import { useModel } from 'umi';
@@ -192,30 +191,30 @@ export default function Page() {
192191
};
193192
```
194193

195-
| Object Property | Type | Introduction |
194+
| Object Property | Type | Description |
196195
| --- | --- | --- |
197196
| `initialState` | `any` | The return value of the exported `getInitialState()` method |
198-
| `loading` | `boolean` | Whether the `getInitialState()` or `refresh()` method is in progress. Before the initial state is first obtained, the rendering of other parts of the page will be **blocked** |
199-
| `error` | `Error` | If the exported `getInitialState()` method throws an error, the error message |
197+
| `loading` | `boolean` | Whether the `getInitialState()` or `refresh()` method is in progress. Before the initial state is obtained for the first time, the rendering of other parts of the page will be **blocked** |
198+
| `error` | `Error` | If an error occurs while running the exported `getInitialState()` method, the error message |
200199
| `refresh` | `() => void` | Re-execute the `getInitialState` method and obtain a new global initial state |
201-
| `setInitialState` | `(state: any) => void` | Manually set the value of `initialState`, after manual setting, `loading` will be set to `false` |
200+
| `setInitialState` | `(state: any) => void` | Manually set the value of `initialState`, after manually setting it, `loading` will be set to `false` |
202201

203-
## Qiankun Parent-Child Application Communication
202+
## Qiankun Parent-Child Communication
204203

205-
`@umi/max` has a built-in **Qiankun Microfrontend** [plugin](https://github.com/umijs/umi/blob/master/packages/plugins/src/qiankun.ts), when using the data stream plugin, it allows micro-applications to obtain the parent application's data Model passed to the child application through the `useModel('@@qiankunStateFromMaster')` method, thereby achieving communication between parent and child applications.
204+
`@umi/max` has a built-in **Qiankun Micro-Frontend** [plugin](https://github.com/umijs/umi/blob/master/packages/plugins/src/qiankun.ts), which allows micro-applications to obtain the data Model passed from the parent application through the `useModel('@@qiankunStateFromMaster')` method, thereby achieving communication between parent and child applications.
206205

207-
For specific usage methods, please refer to the section on parent-child application communication in microfrontend.
206+
For specific usage, please refer to the [micro-frontend's parent-child communication chapter](./micro-frontend#parent-child-communication).
208207

209208
## API
210209

211210
### `useModel`
212211

213-
`useModel()` is a hook function that provides the capability to use Model. It accepts two parameters:
212+
`useModel()` is a hook function that provides the ability to use a Model. It accepts two parameters:
214213

215-
| Parameter | Type | Introduction |
214+
| Parameter | Type | Description |
216215
| --- | --- | --- |
217216
| `namespace` | `String` | The namespace of the Model file |
218-
| `updater` | `(model: any) => any` | An optional parameter. Pass in a function, whose return value is the Model state or data currently needed in the component, and serves as the return value of the `useModel()` method. It is of significant importance for optimizing component performance. |
217+
| `updater` | `(model: any) => any` | Optional parameter. Passing in a function, the return value of which is the Model state or data currently needed by the component, and it serves as the return value of the `useModel()` method. It plays a significant role in optimizing component performance. |
219218

220219
```tsx
221220
// src/components/AdminInfo/index.tsx

0 commit comments

Comments
 (0)