@modern-js/main-doc 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/README.md +2 -2
  4. package/en/apis/app/commands.mdx +2 -0
  5. package/en/apis/app/runtime/model/connect.mdx +1 -1
  6. package/en/apis/app/runtime/model/model_.mdx +1 -1
  7. package/en/apis/app/runtime/model/use-model.mdx +1 -1
  8. package/en/apis/app/runtime/web-server/hook.mdx +2 -2
  9. package/en/apis/app/runtime/web-server/middleware.mdx +33 -9
  10. package/en/components/enable-bff.mdx +4 -4
  11. package/en/components/init-rspack-app.mdx +7 -0
  12. package/en/configure/app/bff/enable-handle-web.mdx +24 -0
  13. package/en/configure/app/server/enable-framework-ext.mdx +1 -1
  14. package/en/guides/advanced-features/bff/_category_.json +1 -1
  15. package/en/guides/advanced-features/eslint.mdx +30 -32
  16. package/en/guides/advanced-features/low-level.mdx +1 -1
  17. package/en/guides/advanced-features/rspack-start.mdx +13 -17
  18. package/en/guides/advanced-features/web-server.mdx +87 -20
  19. package/en/guides/concept/builder.mdx +1 -1
  20. package/en/guides/topic-detail/framework-plugin/extend.mdx +20 -19
  21. package/en/guides/topic-detail/framework-plugin/hook-list.mdx +156 -155
  22. package/en/guides/topic-detail/framework-plugin/hook.mdx +58 -43
  23. package/en/guides/topic-detail/framework-plugin/implement.mdx +47 -49
  24. package/en/guides/topic-detail/framework-plugin/introduction.mdx +22 -23
  25. package/en/guides/topic-detail/framework-plugin/plugin-api.mdx +13 -13
  26. package/en/guides/topic-detail/framework-plugin/relationship.mdx +30 -30
  27. package/en/guides/topic-detail/generator/plugin/develop.mdx +1 -1
  28. package/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +17 -17
  29. package/en/guides/topic-detail/micro-frontend/c02-development.mdx +76 -78
  30. package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +57 -51
  31. package/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +11 -11
  32. package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +13 -13
  33. package/en/guides/topic-detail/model/auto-actions.mdx +18 -21
  34. package/en/guides/topic-detail/model/computed-state.mdx +27 -25
  35. package/en/guides/topic-detail/model/define-model.mdx +14 -14
  36. package/en/guides/topic-detail/model/faq.mdx +12 -13
  37. package/en/guides/topic-detail/model/manage-effects.mdx +43 -52
  38. package/en/guides/topic-detail/model/model-communicate.mdx +47 -45
  39. package/en/guides/topic-detail/model/performance.mdx +22 -23
  40. package/en/guides/topic-detail/model/quick-start.mdx +29 -28
  41. package/en/guides/topic-detail/model/redux-integration.mdx +7 -7
  42. package/en/guides/topic-detail/model/test-model.mdx +11 -11
  43. package/en/guides/topic-detail/model/typescript-best-practice.mdx +16 -15
  44. package/en/guides/topic-detail/model/use-model.mdx +40 -45
  45. package/en/guides/topic-detail/model/use-out-of-modernjs.mdx +16 -16
  46. package/en/guides/troubleshooting/cli.mdx +2 -2
  47. package/package.json +5 -5
  48. package/zh/apis/app/commands.mdx +2 -0
  49. package/zh/apis/app/runtime/model/connect.mdx +1 -1
  50. package/zh/apis/app/runtime/model/model_.mdx +1 -1
  51. package/zh/apis/app/runtime/model/use-model.mdx +1 -1
  52. package/zh/apis/app/runtime/web-server/hook.mdx +2 -4
  53. package/zh/apis/app/runtime/web-server/middleware.mdx +30 -10
  54. package/zh/apis/monorepo/commands/gen-release-note.mdx +3 -3
  55. package/zh/components/enable-bff.mdx +4 -4
  56. package/zh/components/init-rspack-app.mdx +7 -0
  57. package/zh/components/release-note.mdx +1 -1
  58. package/zh/configure/app/bff/enable-handle-web.mdx +24 -0
  59. package/zh/configure/app/server/enable-framework-ext.mdx +1 -1
  60. package/zh/guides/advanced-features/bff/_category_.json +1 -1
  61. package/zh/guides/advanced-features/rspack-start.mdx +13 -17
  62. package/zh/guides/advanced-features/web-server.mdx +81 -16
  63. package/zh/guides/concept/builder.mdx +1 -1
  64. package/zh/guides/topic-detail/changesets/github.mdx +2 -2
  65. package/zh/guides/topic-detail/changesets/release-note.mdx +1 -1
  66. package/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +2 -2
  67. package/zh/guides/topic-detail/generator/plugin/develop.mdx +1 -1
  68. package/zh/guides/topic-detail/model/faq.mdx +1 -1
  69. package/zh/guides/topic-detail/model/manage-effects.mdx +1 -1
  70. package/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
  71. package/zh/guides/topic-detail/model/performance.mdx +1 -1
  72. package/zh/guides/topic-detail/model/quick-start.mdx +2 -2
  73. package/zh/guides/topic-detail/model/use-model.mdx +3 -3
@@ -1,48 +1,48 @@
1
1
  ---
2
2
  sidebar_position: 1
3
- title: 快速上手
3
+ title: Quick Start
4
4
  ---
5
- # 快速上手
5
+ # Quick Start
6
6
 
7
7
  import ReduckMigration from "@site-docs/components/reduck-migration"
8
8
 
9
9
  <ReduckMigration />
10
10
 
11
- [Reduck](https://github.com/modern-js-dev/reduck) Modern.js 团队开发的遵循 MVC 模式的状态管理库,底层状态存储基于 [Redux](https://redux.js.org/) 实现,同时提供更高层级的抽象,并完全兼容 Redux 生态。
11
+ [Reduck](https://github.com/web-infra-dev/reduck) is a state management library developed by the Modern.js team that follows the MVC pattern. Its underlying state storage is based on [Redux](https://redux.js.org/) implementation, while providing a higher level of abstraction and full compatibility with the Redux ecosystem.
12
12
 
13
- Reduck 的目标是以 MVC 模式组织 React 应用开发结构,将业务逻辑维护在 Model 层,业务逻辑与 UI 解耦,让开发业务逻辑更集中、更简单,同时通过更高层级的抽象,减少重复工作(样板代码)。
13
+ The goal of Reduck is to organize the development structure of React applications in the MVC pattern, maintain business logic in the Model layer, decoupling business logic from UI, making it easier for developers to focus on business logic, and reducing duplicated work (boilerplate code) through higher level of abstraction.
14
14
 
15
- Reduck MVC 模式中,扮演 M(Model) 的角色,React UI Component 对应 V(View),从 Reduck 中获取 Model 并修改 Model React Container Component 对应 C(View Controller/Container)
15
+ In the MVC pattern, Reduck plays the role of M(Model), React UI Component corresponds to V(View), and gets the Model from Reduck and modifies the Model's React Container Component, which corresponds to C(View Controller/Container).
16
16
 
17
- Modern.js 的状态管理解决方案,是通过内置 Reduck 实现的。在 Modern.js 中使用 Reduck,不仅免去了手动集成的环节,而且所有 Reduck API 都可以从 Modern.js Runtime 包中直接导入使用,具有更好的一致性体验。
17
+ The state management solution of Modern.js is implemented through built-in Reduck. Using Reduck in Modern.js not only eliminates the manual integration process, but also allows all Reduck APIs to be imported and used directly from the Modern.js Runtime package, providing a better consistency experience.
18
18
 
19
19
  :::info
20
- 1. Modern.js 中使用 Reduck API,需要先设置 [runtime.state](/configure/app/runtime/state) 以启用状态管理插件。
21
- 2. Reduck 也可以脱离 Modern.js 作为状态管理库[单独使用](/guides/topic-detail/model/use-out-of-modernjs)
20
+ 1. To use Reduck APIs in Modern.js, you need to set [runtime.state](/configure/app/runtime/state) to enable the state management plugin.
21
+ 2. Reduck can also be used separately as a state management library [outside of Modern.js](/guides/topic-detail/model/use-out-of-modernjs).
22
22
 
23
23
  :::
24
24
 
25
- ## 核心概念
25
+ ## Core Concepts
26
26
 
27
- Reduck 中的核心概念只有 4 个: ModelStateActionsEffects
27
+ There are only four core concepts in Reduck: Model, State, Actions, and Effects.
28
28
 
29
- Model: 对独立模块的逻辑和所需状态的封装,由 StateActionsEffects 组成。
29
+ Model: Encapsulates the logic and required state of an independent module, consisting of State, Actions, and Effects.
30
30
 
31
- State: Model 中保存的状态。
31
+ State: The state stored in the Model.
32
32
 
33
- Actions: 用于修改 State 的纯函数,函数必须是**同步**的。
33
+ Actions: Pure functions used to modify State, functions must be **Synchronous**.
34
34
 
35
- Effects: 用于修改 State 的带有副作用的函数,函数可以是**异步**的。Effects 中可以调用自身或其他 Model Actions Effects
35
+ Effects: Functions with side effects used to modify State, functions can be **Asynchronous**. Effects can call their own Actions and Effects or those of other Models.
36
36
 
37
- Reduck 数据流如下图所示:
37
+ The Reduck data flow is shown in the following figure:
38
38
 
39
- ![Reduck 数据流](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/reduck-concept.svg)
39
+ ![Reduck Data Flow](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/reduck-concept.svg)
40
40
 
41
- ## 基本用法
41
+ ## Basic Usage
42
42
 
43
- 下来我们以一个简单的 **计数器** 应用为例,演示 Reduck 的基本用法。
43
+ Next, let's take a simple **Counter** application as an example to demonstrate the basic usage of Reduck.
44
44
 
45
- 首先,我们定义一个名为 `count` Model
45
+ First, we define a Model named `count`:
46
46
 
47
47
  ```js
48
48
  import { model } from '@modern-js/runtime/model';
@@ -56,9 +56,9 @@ const countModel = model('count').define({
56
56
  export default countModel;
57
57
  ```
58
58
 
59
- 我们使用 API `model` 创建 `countModel`,`countModel` 当前只包含存储计数器值的状态,即代码中的 `value`。
59
+ We use the API `model` to create `countModel`, which currently only contains the state that stores the counter `value`, that is, value in the code.
60
60
 
61
- 我们定义一个 action,用于计算器自增加 1
61
+ We define an action to increase the counter by 1:
62
62
 
63
63
  ```js
64
64
  import { model } from '@modern-js/runtime/model';
@@ -77,11 +77,11 @@ const countModel = model('count').define({
77
77
  export default countModel;
78
78
  ```
79
79
 
80
- `add` action 中,我们可以直接修改 state 的值,进行加 1 操作,而不需要把 state 作为不可变对象进行操作,这是因为 Reduck 集成了 [immer](https://github.com/immerjs/immer),可以直接修改原 state 对象。
80
+ In the `add` action, we can directly modify the value of the state and perform the increment operation without treating the state as an immutable object. This is because Reduck integrates [immer](https://github.com/immerjs/immer), which can directly modify the original state object.
81
81
 
82
- 接下来,我们演示如何在组件中使用 Model
82
+ Next, we will demonstrate how to use the Model in a component.
83
83
 
84
- 新建一个组件 Counter,在组件内通过 `useModel` API 使用 `countModel`:
84
+ Create a new component called `Counter`, and use the `countModel` via the `useModel` API inside the component:
85
85
 
86
86
  ```js
87
87
  import { useModel } from '@modern-js/runtime/model';
@@ -99,15 +99,16 @@ function Counter() {
99
99
  }
100
100
  ```
101
101
 
102
- `useModel` 获取 `countModel` `state` `actions`,组件展示当前计算器的值,点击 `add` 按钮,计数器自增 1
102
+ `useModel` gets the `state` and `actions` of `countModel`. The component displays the current value of the counter, and clicking the `add` button increments the counter by 1.
103
103
 
104
104
  :::info
105
- 由于使用的案例比较简单,这里并没有严格按照 MVC 模式进行分层,组件 `Counter` 同时起到了 V C 两层的作用。
105
+ Due to the simplicity of the example used here, the layering of the MVC pattern is not strictly followed. The `Counter` component acts as both the V and C layers.
106
106
 
107
107
  :::
108
108
 
109
- 最终演示效果如下:
109
+ The final demonstration effect is as follows:
110
110
 
111
111
  ![countModel](https://lf3-static.bytednsdoc.com/obj/eden-cn/eueh7vhojuh/modern/simple-count-model.gif)
112
112
 
113
- 这样,我们就完了一个简单的计数器应用。本节完整的示例代码可以在[这里](https://github.com/modern-js-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/counter-model)查看。
113
+ That completes a simple counter application. You can view the complete example code for this section [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/counter-model).
114
+
@@ -1,17 +1,18 @@
1
1
  ---
2
2
  sidebar_position: 11
3
- title: Redux 生态集成
3
+ title: Ecosystem Integration
4
4
  ---
5
- # Redux 生态集成
5
+ # Redux Ecosystem Integration
6
6
 
7
- Reduck 基于 Redux 实现,因此可以使用 Redux [生态的库](https://redux.js.org/introduction/ecosystem),实现功能增强。通过 [`Provider`](/apis/app/runtime/model/Provider) [`createApp`](/apis/app/runtime/model/create-app) [`createStore`](/apis/app/runtime/model/create-store) API ,可以设置使用 Redux [中间件](https://redux.js.org/understanding/thinking-in-redux/glossary#middleware) [Store Enhancer](https://redux.js.org/understanding/thinking-in-redux/glossary#store-enhancer);使用 [`createStore`](/apis/app/runtime/model/create-store) 还可以完全掌控 Store 的创建过程。
7
+ Reduck is based on Redux, so you can use libraries from the [Redux ecosystem](https://redux.js.org/introduction/ecosystem) to enhance its functionality. APIs like [`Provider`](/apis/app/runtime/model/Provider), [`createApp`](/apis/app/runtime/model/create-app), and [`createStore`](/apis/app/runtime/model/create-store) allow you to configure the use of [middlewares](https://redux.js.org/understanding/thinking-in-redux/glossary#middleware) and [store enhancers](https://redux.js.org/understanding/thinking-in-redux/glossary#store-enhancer); and using [`createStore`](/apis/app/runtime/model/create-store), you can take complete control over the process of creating the store.
8
+
9
+ For example, if we want to use the middleware [`redux-logger`](https://github.com/LogRocket/redux-logger), the example code is as follows:
8
10
 
9
- 例如,我们希望使用中间件 [`redux-logger`](https://github.com/LogRocket/redux-logger),示例代码如下:
10
11
 
11
12
  ```ts
12
13
  ReactDOM.render(
13
14
  <Provider config={{ middlewares: [logger] }}>
14
- // 通过 Provider config 参数设置 中间件
15
+ // Set middleware through the config parameter of Provider
15
16
  <App />
16
17
  </Provider>,
17
18
  document.getElementById('root'),
@@ -19,6 +20,5 @@ ReactDOM.render(
19
20
  ```
20
21
 
21
22
  :::caution
22
- Reduck 基于 Redux 底层 API 做了上层封装,屏蔽了 Redux 的一些底层概念,如 Reducer 等。Reduck 对于 Model 是动态挂载的,而 Redux 是在 Store 创建时就会挂载应用所需的全部状态。基于这些实现上的差异,有些 Redux 生态的库是无法直接在 Reduck 中使用的。
23
-
23
+ Reduck is built on top of the lower-level Redux API, and abstracts away some of the underlying concepts of Redux, such as Reducers. Reduck allows models to be dynamically mounted, whereas Redux mounts all the necessary state at Store creation time. Due to these implementation differences, some libraries from the Redux ecosystem cannot be used directly in Reduck.
24
24
  :::
@@ -1,21 +1,21 @@
1
1
  ---
2
2
  sidebar_position: 9
3
- title: 测试 Model
3
+ title: Test Model
4
4
  ---
5
- # 测试 Model
5
+ # Test Model
6
6
 
7
- 好的测试对代码的稳健性至关重要。下面以 [快速上手](/guides/topic-detail/model/quick-start) `countModel` 为例,演示在 Modern.js 中,如何对 Model 进行单元测试。
7
+ Testing is crucial for the stability of code. Here's an example using the `countModel` from [Quick Start](/guides/topic-detail/model/quick-start) to demonstrate how to perform unit testing on a Model in Modern.js.
8
8
 
9
- 使用测试功能,需要先开启该功能。在项目根目录下,执行 `pnpm run new`,进行如下选择:
9
+ To use the testing feature, you need to first enable it. In the project root directory, execute `pnpm run new` and make the following selection:
10
10
 
11
11
  ```bash
12
- ? 请选择你想要的操作 启用可选功能
13
- ? 启用可选功能 启用「单元测试 / 集成测试」功能
12
+ ? Please select the operation you want to perform: Enable optional features
13
+ ? Enable optional features Enable "Unit Testing / Integration Testing" feature
14
14
  ```
15
15
 
16
- 即可开启测试功能支持。
16
+ This will enable testing feature support.
17
17
 
18
- 新增 `count.test.ts` 文件,代码如下:
18
+ Create a new file called `count.test.ts` with the following code:
19
19
 
20
20
  ```ts
21
21
  import { createStore } from '@modern-js/runtime/testing';
@@ -36,10 +36,10 @@ describe('test model', () => {
36
36
  ```
37
37
 
38
38
  :::info
39
- 这里使用的 [`createStore`](/apis/app/runtime/model/create-store) 是从 `@modern-js/runtime/testing` 导入的,内部会使用 [`runtime.state`](/configure/app/runtime/state) 的配置去创建 `store`。
39
+ The [`createStore`](/apis/app/runtime/model/create-store) used here is imported from `@modern-js/runtime/testing`, which internally uses the configuration of [`runtime.state`](/configure/app/runtime/state) to create a `store`.
40
40
 
41
41
  :::
42
42
 
43
- 在测试用例里,我们新建一个 `store` 来挂载 `countModel`,通过 `store.use` 获取 `countModel` State Actions。然后调用 `add` Action 更新状态,并断言更新后的状态值。
43
+ In the test case, we create a new `store` to mount `countModel`, use `store.use` to get the State and Actions of `countModel`. Then, we call the `add` Action to update the state and assert the updated state value.
44
44
 
45
- 执行 `pnpm run test` 命令,触发测试用例的执行。
45
+ Execute the `pnpm run test` command to trigger the execution of the test case.
@@ -1,16 +1,16 @@
1
1
  ---
2
2
  sidebar_position: 10
3
- title: TS 最佳实践
3
+ title: TS Best Practices
4
4
  ---
5
- # TS 最佳实践
5
+ # TS Best Practices
6
6
 
7
- Reduck TS 提供了良好的支持,大部分使用场景下,无需任何额外工作,就可以直接获得 API TS 类型提示。本节,将对其他的一些使用场景,做补充介绍。
7
+ Reduck provides excellent support for TypeScript, and in most cases, you can get API type prompts directly without any extra work. In this section, we will provide additional information on other usage scenarios.
8
8
 
9
- ## 定义 Model State 类型
9
+ ## Defining the State Type of the Model
10
10
 
11
- Model State 声明类型信息,是在 TS 中使用 Reduck 的最佳实践。
11
+ Declaring type information for the State of a Model is a best practice when using Reduck in TypeScript.
12
12
 
13
- ```ts title="示例"
13
+ ```ts
14
14
  interface State {
15
15
  data: string;
16
16
  }
@@ -30,13 +30,14 @@ export const foo = model<State>('foo').define({
30
30
  });
31
31
  ```
32
32
 
33
- 当为 Model State 声明类型信息后,Model `computed`、`actions` 都能获取正确的类型信息。事实上,上面的示例代码中,即使我们不定义 State 类型信息,也会根据 `state` 的初始值信息自动推导出 State 的类型信息。不过,仍然建议你在定义 Model 时,声明 State 的类型信息,因为根据 `state` 的初始值信息推导出的 State 类型信息可能不完整(缺少字段或字段的类型信息缺少),而且当使用[函数类型](/apis/app/runtime/model/model_#函数类型)定义 Model 时,State 的类型信息也是无法根据 `state` 的初始值信息自动推导的。
33
+ When you declare type information for the State of a Model, the `computed` and `actions` of the Model can get the correct type information. In fact, even if we don't define State type information in the example code above, the type information of State can be automatically inferred based on the initial value information of `state`. However, we still recommend that you declare the type information of State when defining a Model because the type information of State inferred based on the initial value information of `state` may be incomplete (missing fields or field type information), and the type information of State cannot be automatically inferred based on the initial value information of `state` when using [Function Type](/apis/app/runtime/model/model_#函数类型) to define the Model.
34
34
 
35
- ## 衍生状态的依赖类型
35
+ ## Dependent types of Derived State
36
36
 
37
- Model 的衍生状态依赖其他 Model 时,需要手动指定其他 Model State
37
+ When the derived state of a Model depends on other Models, you need to manually specify the State of the other Models.
38
38
 
39
- ```ts title="示例"
39
+
40
+ ```ts
40
41
  interface State {
41
42
  data: string;
42
43
  }
@@ -52,14 +53,14 @@ export const bar = model<State>('bar').define({
52
53
  });
53
54
  ```
54
55
 
55
- ## 获取 Model 类型信息的 Hooks
56
+ ## Hooks for Getting Model Type Information
56
57
 
57
- Reduck 提供了一组用于获取 Model 类型信息的工具类型:
58
+ Reduck provides a set of utility types for getting Model type information:
58
59
 
59
- - `GetModelState`: 获取 Model State(包含衍生状态)类型信息。
60
- - `GetModelActions`:获取 Model Actions(包含 Effects 函数)类型信息。
60
+ - `GetModelState`: Get the type information of the State (including derived state) of the Model.
61
+ - `GetModelActions`: Get the type information of the Actions (including Effects functions) of the Model.
61
62
 
62
- ```ts title="示例"
63
+ ```ts
63
64
  export const foo = model<State2>('foo').define({
64
65
  // 省略
65
66
  });
@@ -1,18 +1,18 @@
1
1
  ---
2
2
  sidebar_position: 3
3
- title: 使用 Model
3
+ title: Use Models
4
4
  ---
5
- # 使用 Model
5
+ # Use Models
6
6
 
7
- ## 在组件内使用
7
+ ## Using Models in Components
8
8
 
9
- ### 作为全局状态使用
9
+ ### Using as Global State
10
10
 
11
- 通过 `useModel` 可以获取 Model StateActions 等。当 Model State 通过 Actions 进行修改后,任何其他使用了该 Model 的组件,都会自动重新渲染。
11
+ `useModel` can be used to obtain the State, Actions, and other information of the Model. When the State of the Model is modified by Actions, any other components that use the Model will automatically re-render.
12
12
 
13
- [快速上手](/guides/topic-detail/model/quick-start) 的计数器案例中,我们已经演示了 `useModel` 的使用,不再重复。
13
+ In the counter example in [Quick Start](/guides/topic-detail/model/quick-start), we have demonstrated the use of `useModel` and will not repeat it here.
14
14
 
15
- `useModel` 支持传入多个 Model,多个 Model State Actions 会进行合并后作为返回结果。例如:
15
+ `useModel` supports passing multiple Models, and the State and Actions of multiple Models will be merged and returned as the result. For example:
16
16
 
17
17
  ```ts
18
18
  const fooModel = model('foo').define({
@@ -42,7 +42,7 @@ const [state, actions] = useModel([fooModel, barModel]);
42
42
  const [state, actions] = useModel(fooModel, barModel);
43
43
  ```
44
44
 
45
- `state` `actions` 的值分别为:
45
+ `state` and `actions` value are:
46
46
 
47
47
  ```ts
48
48
  state = {
@@ -60,7 +60,7 @@ actions = {
60
60
  };
61
61
  ```
62
62
 
63
- `useModel` 还支持对 State Actions selector 操作,实现对 State Actions 的筛选或重命名,例如:
63
+ `useModel` also supports selector operations on State and Actions to filter or rename State and Actions. For example:
64
64
 
65
65
  ```ts
66
66
  const fooModel = model('foo').define({
@@ -95,9 +95,9 @@ const [state, actions] = useModel(
95
95
  );
96
96
  ```
97
97
 
98
- 我们通过 `stateSelector` ,把 `fooModel` `barModel` 中重名的状态做了命名修改,通过 `actionsSelector` ,过滤掉了 `barModel` Actions
98
+ We use `stateSelector` to rename the states with the same name in `fooModel` and `barModel`. We use `actionsSelector` to filter out the Actions of `barModel`.
99
99
 
100
- 如果只需要设置 `actionsSelector`,可以把 `stateSelector` 设置为 `undefined`,作为参数占位。例如:
100
+ If only `actionsSelector` needs to be set, you can set `stateSelector` to `undefined` as a placeholder. For example:
101
101
 
102
102
  ```ts
103
103
  const [state, actions] = useModel(
@@ -107,22 +107,21 @@ const [state, actions] = useModel(
107
107
  );
108
108
  ```
109
109
 
110
- ### 作为静态状态使用
110
+ ### Using as Static State
111
111
 
112
- 通过 `useStaticModel` 获取 Model ,将 Model 中的状态作为静态状态使用。可以保证组件每次访问到的 Model State 都是最新值,但是 Model State 的变化,并不会引起当前组件的重新渲染。
112
+ `useStaticModel` can be used to obtain the Model and use the state of the Model as a static state. This ensures that the State accessed by the component is always the latest value, but the change of the Model's State does not cause the current component to re-render.
113
113
 
114
114
  :::info
115
- `useStaticModel` 的使用方式和 `useModel` 完全一致。
116
-
115
+ The usage of `useStaticModel` is exactly the same as `useModel`.
117
116
  :::
118
117
 
119
- 考虑下面一种场景,有一个组件 Input 负责用户输入,另外一个组件 Search 负责根据用户的输入信息,在点击查询按钮后执行查询操作,我们不希望用户输入过程中的状态变化引起 Search 重新渲染,这时候就可以使用 `useStaticModel`:
118
+ Consider the following scenario: there is an Input component responsible for user input, and another Search component responsible for executing a search operation after the user input information is entered and the search button is clicked. We do not want the state changes during the user input process to cause Search to re-render. In this case, `useStaticModel` can be used:
120
119
 
121
120
  ```ts
122
121
  import { useStaticModel } from '@modern-js/runtime/model';
123
122
 
124
123
  function Search() {
125
- // 这里注意不要解构 state
124
+ // should not be destructured
126
125
  const [state] = useStaticModel(searchModel);
127
126
 
128
127
  return (
@@ -140,41 +139,40 @@ function Search() {
140
139
  }
141
140
  ```
142
141
 
143
- :::warning 注意
144
- 不要解构 `useStaticModel` 返回的 `state`,例如改成如下写法:
142
+ :::warning Caution
143
+ Do not destructure the `state` returned by `useStaticModel`. For example, changing it to the following code:
145
144
  `const [{input}] = useStaticModel(searchModel);`
146
- 将始终获取到 Input 的初始值。
145
+ will always get the initial value of Input.
147
146
 
148
147
  :::
149
148
 
150
- `useStaticModel` 还适合和 [react-three-fiber](https://github.com/pmndrs/react-three-fiber) 等动画库一起使用,因为在动画组件 UI 里绑定会快速变化的状态,容易引起[性能问题](https:/docs.pmnd.rs/react-three-fiber/advanced/pitfalls#never-bind-fast-state-reactive)。这种情况就可以选择使用 `useStaticModel`,它只会订阅状态,但不会引起视图组件的重新渲染。下面是一个简化示例:
149
+ `useStaticModel` is also suitable for use with animation libraries such as [react-three-fiber](https://github.com/pmndrs/react-three-fiber), because binding fast-changing states in animation component UI can easily cause [performance issues](https:/docs.pmnd.rs/react-three-fiber/advanced/pitfalls#never-bind-fast-state-reactive). In this case, you can choose to use `useStaticModel`, which only subscribes to the State but does not cause the view component to re-render. Here is a simplified example:
151
150
 
152
151
  ```ts
153
152
  function ThreeComponent() {
154
153
  const [state, actions] = useStaticModel(modelA);
155
154
 
156
155
  useFrame(() => {
157
- state.value; // 假设初始化为 0
156
+ state.value;
158
157
  actions.setValue(1);
159
- state.value; // 这里会得到1
158
+ state.value;
160
159
  });
161
160
  }
162
161
  ```
163
162
 
164
- 使用 React refs 也可以实现类似效果,其实 `useStaticModel` 内部也使用到了 refs。不过直接 `useStaticModel` 有助于将状态的管理逻辑从组件中解耦,统一收敛到 Model 层。
163
+ Using React's refs can also achieve similar effects. In fact, `useStaticModel` also uses refs internally. However, using `useStaticModel` directly helps decouple the state management logic from the component and converge it into the Model layer.
165
164
 
166
- 完整的示例代码可以在[这里](https://github.com/modern-js-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/static-model)查看。
165
+ The complete sample code can be found [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/static-model).
167
166
 
168
- ### 作为局部状态使用
167
+ ### Using as Local State
169
168
 
170
- 通过 `useLocalModel` 获取 Model ,将 Model 中的状态作为局部状态使用。此时 Model State 的变化,只会引起当前组件的重新渲染,但是不会引起其他使用了该 Model 的组件重新渲染。效果和通过 React `useState` 管理状态类似,但是可以将状态的管理逻辑从组件中解耦,统一收敛到 Model 层。
169
+ `useLocalModel` can be used to obtain the Model and use the state of the Model as local state. At this time, the change of the Model State only causes the current component to re-render, but does not cause other components that use the Model to re-render. The effect is similar to managing state through `useState` in React, but it can decouple the state management logic from the component and converge it into the Model layer.
171
170
 
172
171
  :::info
173
- `useLocalModel` 的使用方式和 `useModel` 完全一致。
174
-
172
+ The usage of `useLocalModel` is exactly the same as `useModel`.
175
173
  :::
176
174
 
177
- 例如,我们修改计数器应用的代码,添加一个有局部状态的计数器组件 `LocalCounter`:
175
+ For example, we modify the code of the counter application and add a counter component `LocalCounter` with local state:
178
176
 
179
177
  ```ts
180
178
  import { useLocalModel } from '@modern-js/runtime/model';
@@ -191,20 +189,20 @@ function LocalCounter() {
191
189
  }
192
190
  ```
193
191
 
194
- 分别点击 `Counter` `LocalCounter` `add` 按钮,两者的状态互不影响:
192
+ Click the `add` button of `Counter` and `LocalCounter` respectively, and the states of the two do not affect each other:
195
193
 
196
194
  ![local-model](https://lf3-static.bytednsdoc.com/obj/eden-cn/eueh7vhojuh/modern/local-model.gif)
197
195
 
198
- 完整的示例代码可以在[这里](https://github.com/modern-js-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/local-model)查看。
196
+ The complete sample code can be found [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/local-model).
199
197
 
200
- ## 在组件外使用
198
+ ## Using outside of components
201
199
 
202
- 在实际业务场景中,有时候我们需要在 React 组件外使用 Model,例如在工具函数中访问 State、执行 Actions 等。这个时候,我们就需要使用 Store Store 是一个底层概念,一般情况下用户接触不到,它负责存储和管理整个应用的状态。Reduck Store 基于 [Redux Store](https://redux.js.org/api/store) 实现,增加了 Reduck 特有的 API,如 `use` 。
200
+ In actual business scenarios, sometimes we need to use Model outside of React components, such as accessing State and executing Actions in utility functions. At this time, we need to use the Store. The Store is a low-level concept that users generally cannot touch. It is responsible for storing and managing the entire application's state. Reduck's Store is based on Redux's Store implementation and adds Reduck-specific APIs, such as `use`.
203
201
 
204
- 首先,在组件内调用 `useStore` 获取当前应用使用的 `store` 对象,并挂载到组件外的变量上:
202
+ First, call `useStore` in the component to obtain the `store` object used by the current application and mount it to a variable outside the component:
205
203
 
206
204
  ```ts
207
- let store; // 组件外部 `store` 对象的引用
205
+ let store; // Reference to `store` object outside of the component
208
206
  function setStore(s) {
209
207
  store = s;
210
208
  }
@@ -215,7 +213,7 @@ function getStore() {
215
213
  function Counter() {
216
214
  const [state] = useModel(countModel);
217
215
  const store = useStore();
218
- // 通过 useMemo 避免不必要的重复设置
216
+ // Avoid unnecessary duplicate settings through `useMemo`
219
217
  useMemo(() => {
220
218
  setStore(store);
221
219
  }, [store]);
@@ -228,8 +226,7 @@ function Counter() {
228
226
  }
229
227
  ```
230
228
 
231
- 通过 `store.use` 可以获取 Model 对象,`store.use` 的用法同 `useModel` 相同。以计数器应用为例,我们在组件树外,每 1s 对计数器值
232
- 执行自增操作:
229
+ You can obtain the Model object through `store.use`, and the usage of `store.use` is the same as `useModel`. Taking the counter application as an example, we perform an increment operation on the counter value every 1 second outside the component tree:
233
230
 
234
231
  ```ts
235
232
  setInterval(() => {
@@ -239,14 +236,12 @@ setInterval(() => {
239
236
  }, 1000);
240
237
  ```
241
238
 
242
- 完整的示例代码可以在[这里](https://github.com/modern-js-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/counter-model-outof-react)查看。
239
+ The complete sample code can be found [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/series/tutorials/runtime-api/model/counter-model-outof-react).
243
240
 
244
241
  :::info
245
- 如果是通过 [`createStore`](/apis/app/runtime/model/create-store) 手动创建的 Store 对象,无需通过 `useStore` 在组件内获取,即可直接使用。
246
-
242
+ If the Store object is manually created through [`createStore`](/apis/app/runtime/model/create-store), there is no need to obtain it through `useStore` in the component, and it can be used directly.
247
243
  :::
248
244
 
249
- :::info 补充信息
250
- 本节涉及的 API 的详细定义,请参考[这里](/apis/app/runtime/model/model_)
251
-
245
+ :::info Additional Information
246
+ For detailed API definitions related to this section, please refer to [here](/apis/app/runtime/model/model_).
252
247
  :::
@@ -1,47 +1,47 @@
1
1
  ---
2
2
  sidebar_position: 12
3
- title: 单独使用 Reduck
3
+ title: Using Reduck Separately
4
4
  ---
5
- # 单独使用 Reduck
5
+ # Using Reduck Separately
6
6
 
7
- Modern.js 以外,单独集成 Reduck 使用时,主要需要做以下修改:
7
+ When integrating Reduck separately from Modern.js, the following modifications need to be made:
8
8
 
9
- 1. 安装 Reduck 相关包
9
+ 1. Install the Reduck related packages
10
10
 
11
- 在项目中安装 Reduck 包:`@modern-js-reduck/react`。
11
+ Install the Reduck package in the project: `@modern-js-reduck/react`.
12
12
 
13
- 2. API 导入包名
13
+ 2. Import package names for API
14
14
 
15
- Modern.js 中使用时,Reduck 导出 API 的包名为:`@modern-js/runtime/model`。单独使用 Reduck 时,导出包名为:`@modern-js-reduck/react`。
15
+ When used in Modern.js, the package name for exporting Reduck API is: `@modern-js/runtime/model`. When using Reduck separately, the package name for exporting is: `@modern-js-reduck/react`.
16
16
 
17
- 3. 包裹 `Provider` 组件
17
+ 3. Wrap the `Provider` component
18
18
 
19
- Modern.js 自动在应用的入口组件上,包裹了用于注入 Reduck 全局 Store 的 [`Provider`](/apis/app/runtime/model/Provider) 组件。单独使用 Reduck 时,需要手动完成。
19
+ Modern.js automatically wraps the [`Provider`](/apis/app/runtime/model/Provider) component used to inject the Reduck global Store on the entry component of the application. When using Reduck separately, this needs to be done manually.
20
20
 
21
- 示例:
21
+ Example:
22
22
 
23
23
  ```tsx
24
- // 根组件
24
+ // Root Component
25
25
  const Root = () => {
26
26
  return (
27
27
  <Provider>
28
- {/* 应用入口组件 */}
28
+ {/* Entry App */}
29
29
  <App />
30
30
  </Provider>
31
31
  );
32
32
  };
33
33
  ```
34
34
 
35
- 4. 功能配置
35
+ 4. Feature configuration
36
36
 
37
- Modern.js 中使用时,可以通过 [`runtime.state`](/configure/app/runtime/state) Reduck 功能进行配置。单独使用时,需要通过 [`Provider`](/apis/app/runtime/model/Provider) 的 `config` 或 `store` 参数配置。
37
+ When used in Modern.js, Reduck features can be configured through [`runtime.state`](/configure/app/runtime/state). When used separately, configuration needs to be done through the `config` or `store` parameter of [`Provider`](/apis/app/runtime/model/Provider).
38
38
 
39
- 示例:
39
+ Example:
40
40
 
41
41
  ```tsx
42
42
  const Root = () => {
43
43
  return (
44
- {/* 关闭 Redux DevTools */}
44
+ {/* Close Redux DevTools */}
45
45
  <Provider config={{ devTools: false }}>
46
46
  <App />
47
47
  </Provider>
@@ -58,6 +58,6 @@ In the above example the parameter `--option` is passed to `modern command`. If
58
58
 
59
59
  Summary:
60
60
 
61
- ** When using pnpm v7, if you pass arguments to pnpm, you need to put the arguments before the command **
61
+ **When using pnpm v7, if you pass arguments to pnpm, you need to put the arguments before the command**
62
62
 
63
- ** When using pnpm v6, if the parameter passed to pnpm, you do not need to add `--`; if the parameter passed is for script use, you need to add `--` character string **.
63
+ **When using pnpm v6, if the parameter passed to pnpm, you do not need to add `--`; if the parameter passed is for script use, you need to add `--` character string**.
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@modern-js/main-doc",
3
3
  "description": "Shared documentation of modern.js framework",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": "web-infra-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
9
  "react",
@@ -11,13 +11,13 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.7.0",
14
+ "version": "2.8.0",
15
15
  "publishConfig": {
16
16
  "registry": "https://registry.npmjs.org/",
17
17
  "access": "public"
18
18
  },
19
19
  "peerDependencies": {
20
- "@modern-js/builder-doc": "^2.7.0"
20
+ "@modern-js/builder-doc": "^2.8.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "ts-node": "^10",
@@ -25,7 +25,7 @@
25
25
  "fs-extra": "^10",
26
26
  "@types/node": "^16",
27
27
  "@types/fs-extra": "^9",
28
- "@modern-js/builder-doc": "2.7.0"
28
+ "@modern-js/builder-doc": "2.8.0"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "npx ts-node ./scripts/sync.ts"
@@ -20,6 +20,7 @@ Options:
20
20
  -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
21
21
  -h, --help 显示命令帮助
22
22
  --analyze 分析构建产物体积,查看各个模块打包后的大小
23
+ --web-only 仅启动 Web 服务
23
24
  --api-only 仅启动 API 接口服务
24
25
  ```
25
26
 
@@ -161,6 +162,7 @@ Usage: modern serve [options]
161
162
  Options:
162
163
  -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
163
164
  -h, --help 显示命令帮助
165
+ --web-only 仅启动 Web 服务
164
166
  --api-only 仅启动 API 接口服务
165
167
  ```
166
168
 
@@ -9,7 +9,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
9
9
  <ReduckTip />
10
10
 
11
11
  :::tip 提示
12
- Reduck 原始类型较为复杂,以下涉及类型定义的地方,展示的是简化后的类型信息。原始类型见 [**connect**](https://github.com/modern-js-dev/reduck/blob/main/packages/react/src/connect.ts)。
12
+ Reduck 原始类型较为复杂,以下涉及类型定义的地方,展示的是简化后的类型信息。原始类型见 [**connect**](https://github.com/web-infra-dev/reduck/blob/main/packages/react/src/connect.ts)。
13
13
 
14
14
  :::
15
15
 
@@ -9,7 +9,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
9
9
  <ReduckTip />
10
10
 
11
11
  :::tip 提示
12
- Reduck 原始类型较为复杂,以下涉及类型定义的地方,展示的是简化后的类型信息。原始类型见 [**model**](https://github.com/modern-js-dev/reduck/blob/main/packages/store/src/model/model.ts)。
12
+ Reduck 原始类型较为复杂,以下涉及类型定义的地方,展示的是简化后的类型信息。原始类型见 [**model**](https://github.com/web-infra-dev/reduck/blob/main/packages/store/src/model/model.ts)。
13
13
 
14
14
  :::
15
15