@modern-js/main-doc 2.66.0 → 2.66.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/apis/app/hooks/src/app.mdx +20 -34
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/en/apis/app/runtime/app/define-config.mdx +6 -0
- package/docs/en/apis/app/runtime/web-server/hook.mdx +5 -0
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -23
- package/docs/en/components/enable-micro-frontend.mdx +20 -3
- package/docs/en/components/micro-runtime-config.mdx +12 -13
- package/docs/en/components/reduck-notify.mdx +27 -0
- package/docs/en/components/runtime-cli-config.mdx +0 -0
- package/docs/en/configure/app/runtime/0-intro.mdx +66 -90
- package/docs/en/configure/app/usage.mdx +93 -69
- package/docs/en/guides/advanced-features/web-server.mdx +38 -102
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +115 -0
- package/docs/en/guides/basic-features/routes.mdx +0 -95
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -4
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -5
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -4
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -5
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -5
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -5
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -4
- package/docs/en/guides/topic-detail/model/quick-start.mdx +5 -7
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -4
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -5
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
- package/docs/zh/apis/app/hooks/src/app.mdx +18 -26
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/zh/apis/app/runtime/app/define-config.mdx +5 -0
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +4 -0
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +2 -23
- package/docs/zh/components/enable-micro-frontend.mdx +19 -12
- package/docs/zh/components/micro-runtime-config.mdx +3 -3
- package/docs/zh/components/reduck-notify.mdx +27 -0
- package/docs/zh/components/runtime-cli-config.mdx +0 -0
- package/docs/zh/configure/app/runtime/0-intro.mdx +71 -86
- package/docs/zh/configure/app/usage.mdx +44 -21
- package/docs/zh/guides/advanced-features/web-server.mdx +35 -97
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +115 -0
- package/docs/zh/guides/basic-features/routes.mdx +0 -95
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/define-model.mdx +1 -4
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -5
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +1 -4
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +7 -8
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -5
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
- package/package.json +1 -1
- package/docs/en/configure/app/server/enable-framework-ext.mdx +0 -49
- package/docs/zh/configure/app/server/enable-framework-ext.mdx +0 -49
@@ -483,101 +483,6 @@ Modern.js 支持通过 `loading.tsx` 文件来解决这个问题,`routes/` 下
|
|
483
483
|
:::
|
484
484
|
|
485
485
|
|
486
|
-
## 运行时配置
|
487
|
-
|
488
|
-
{/* Todo 移到动运行时配置章节 */}
|
489
|
-
|
490
|
-
在根 `<Layout>` 组件中(`routes/layout.ts`),可以动态地定义运行时配置:
|
491
|
-
|
492
|
-
```tsx title="src/routes/layout.tsx"
|
493
|
-
// 定义运行时配置
|
494
|
-
import type { AppConfig } from '@modern-js/runtime';
|
495
|
-
|
496
|
-
export const config = (): AppConfig => {
|
497
|
-
return {
|
498
|
-
router: {
|
499
|
-
createRoutes() {
|
500
|
-
return [
|
501
|
-
{
|
502
|
-
path: 'modern',
|
503
|
-
element: <div>modern</div>,
|
504
|
-
},
|
505
|
-
];
|
506
|
-
},
|
507
|
-
},
|
508
|
-
};
|
509
|
-
};
|
510
|
-
```
|
511
|
-
|
512
|
-
## 渲染前的钩子
|
513
|
-
|
514
|
-
{/* Todo 移到动运行时配置章节 */}
|
515
|
-
|
516
|
-
在有些场景下,需要在应用渲染前做一些操作,可以在 `routes/layout.tsx` 中定义 `init` 钩子,`init` 在客户端和服务端均会执行,基本使用示例如下:
|
517
|
-
|
518
|
-
```ts title="src/routes/layout.tsx"
|
519
|
-
import type { RuntimeContext } from '@modern-js/runtime';
|
520
|
-
|
521
|
-
export const init = (context: RuntimeContext) => {
|
522
|
-
// do something
|
523
|
-
};
|
524
|
-
```
|
525
|
-
|
526
|
-
通过 `init` 钩子可以挂载一些全局的数据,在应用的其他地方可以访问 `runtimeContext` 变量:
|
527
|
-
|
528
|
-
:::note
|
529
|
-
该功能在应用需要页面前置的数据、自定义数据注入或是框架迁移(如 Next.js)时会非常有用。
|
530
|
-
|
531
|
-
:::
|
532
|
-
|
533
|
-
```ts title="src/routes/layout.tsx"
|
534
|
-
import { RuntimeContext } from '@modern-js/runtime';
|
535
|
-
|
536
|
-
type InitialData = {
|
537
|
-
message: string;
|
538
|
-
}
|
539
|
-
|
540
|
-
export const init = (context: RuntimeContext): InitialData => {
|
541
|
-
return {
|
542
|
-
message: 'Hello World',
|
543
|
-
};
|
544
|
-
};
|
545
|
-
```
|
546
|
-
|
547
|
-
```tsx title="src/routes/page.tsx"
|
548
|
-
import { useRuntimeContext } from '@modern-js/runtime';
|
549
|
-
|
550
|
-
export default () => {
|
551
|
-
const context = useRuntimeContext();
|
552
|
-
const { message } = context.initialData as InitialData;
|
553
|
-
|
554
|
-
return <div>{message}</div>;
|
555
|
-
};
|
556
|
-
```
|
557
|
-
|
558
|
-
配合 SSR 功能时,浏览器端可以获取到 SSR 时 `init` 返回的数据,开发者可以自行判断是否要在浏览器端重新获取数据来覆盖 SSR 数据,例如:
|
559
|
-
|
560
|
-
```tsx title="src/routes/layout.tsx"
|
561
|
-
import type { RuntimeContext } from '@modern-js/runtime';
|
562
|
-
|
563
|
-
export const init = (runtimeContext: RuntimeContext) => {
|
564
|
-
if (process.env.MODERN_TARGET === 'node') {
|
565
|
-
return {
|
566
|
-
message: 'Hello World By Server',
|
567
|
-
};
|
568
|
-
} else {
|
569
|
-
const { context } = runtimeContext;
|
570
|
-
const data = context.getInitData();
|
571
|
-
// 如果没有获取到期望的数据
|
572
|
-
if (!data.message) {
|
573
|
-
return {
|
574
|
-
message: 'Hello World By Client',
|
575
|
-
};
|
576
|
-
}
|
577
|
-
}
|
578
|
-
};
|
579
|
-
```
|
580
|
-
|
581
486
|
import Motivation from '@site-docs/components/convention-routing-motivation';
|
582
487
|
|
583
488
|
<Motivation />
|
@@ -14,9 +14,9 @@ title: 体验微前端
|
|
14
14
|
|
15
15
|
目前项目的路由模式分为以下三种
|
16
16
|
|
17
|
-
- 约定式路由
|
18
|
-
- 自控式路由
|
19
|
-
- 其他 (
|
17
|
+
- [约定式路由](/guides/concept/entries.html#约定式路由)
|
18
|
+
- [自控式路由](/guides/concept/entries.html#自控式路由)
|
19
|
+
- 其他 (项目自行安装和使用 `react-router-dom`)
|
20
20
|
|
21
21
|
在本教程中我们会为主应用创建两个子应用 Table 和 Dashboard (Table 为约定式路由,Dashboard 为自控式路由)
|
22
22
|
|
@@ -206,7 +206,6 @@ export default defineConfig({
|
|
206
206
|
},
|
207
207
|
runtime: {
|
208
208
|
router: true,
|
209
|
-
state: true,
|
210
209
|
},
|
211
210
|
deploy: {
|
212
211
|
microFrontend: true,
|
@@ -259,7 +258,6 @@ export default defineConfig({
|
|
259
258
|
},
|
260
259
|
runtime: {
|
261
260
|
router: true,
|
262
|
-
state: true,
|
263
261
|
},
|
264
262
|
deploy: {
|
265
263
|
microFrontend: true,
|
@@ -35,8 +35,10 @@ import MicroRuntimeConfig from '@site-docs/components/micro-runtime-config';
|
|
35
35
|
|
36
36
|
通过该函数可以拉取远程的子应用列表,并将其注册至运行时框架:
|
37
37
|
|
38
|
-
```ts title="
|
39
|
-
|
38
|
+
```ts title="src/modern.runtime.ts"
|
39
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
40
|
+
|
41
|
+
export default defineRuntimeConfig({
|
40
42
|
masterApp: {
|
41
43
|
manifest: {
|
42
44
|
getAppList: async () => {
|
@@ -1,7 +1,3 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 2
|
3
|
-
title: 创建 Model
|
4
|
-
---
|
5
1
|
# 创建 Model
|
6
2
|
|
7
3
|
上一节的计数器应用中,我们简单演示了如何创建一个 Model。本节我们将详细介绍 Model 的创建方法。
|
@@ -24,6 +20,7 @@ const fooModel = model('foo').define({
|
|
24
20
|
```
|
25
21
|
|
26
22
|
:::info
|
23
|
+
|
27
24
|
- Model 中的 Action 中不能包含有副作用的逻辑,如请求 HTTP 接口,访问 localStorage 等。
|
28
25
|
- `setValue` 内部直接修改了入参 State,看起来是违反了纯函数的定义,实际上 Reduck 内部使用 [immer](https://github.com/immerjs/immer) 来修改不可变对象,保证了这种写法不会影响对象的不可变性,所以 `setValue` 仍然是一个纯函数。当然,你也可以直接在 Action 中返回一个新对象,不过这样的写法会更加复杂一些。
|
29
26
|
|
@@ -1,7 +1,3 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 7
|
3
|
-
title: Model 通信
|
4
|
-
---
|
5
1
|
# Model 通信
|
6
2
|
|
7
3
|
Model 通信,既指不同 Model 间的通信,也指同一个 Model 内部 Effects、Actions 之间的通信。
|
@@ -100,6 +96,7 @@ Modern.js 默认开启 [自动生成 actions](./auto-actions.mdx),所以 `step
|
|
100
96
|

|
101
97
|
|
102
98
|
:::info 补充信息
|
99
|
+
|
103
100
|
- 本节完整的[示例代码](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/models-communication)。
|
104
101
|
- 相关 API 的更多介绍,请参考:[model](/apis/app/runtime/model/model_#函数类型)。
|
105
102
|
|
@@ -1,15 +1,14 @@
|
|
1
|
-
|
2
|
-
sidebar_position: 1
|
3
|
-
title: 快速上手
|
4
|
-
---
|
1
|
+
# 快速上手
|
5
2
|
|
6
3
|
:::caution
|
7
4
|
新项目不再推荐使用 Reduck,可以使用社区中的状态管理工具,例如 [Jotai](https://jotai.org/)、[zustand](https://zustand.docs.pmnd.rs/getting-started/introduction)、[valtio](https://valtio.dev/docs/introduction/getting-started) 等。
|
8
5
|
:::
|
9
6
|
|
10
|
-
|
7
|
+
import ReduckNotify from '@site-docs/components/reduck-notify';
|
11
8
|
|
12
|
-
|
9
|
+
<ReduckNotify />
|
10
|
+
|
11
|
+
import ReduckMigration from '@site-docs/components/reduck-migration';
|
13
12
|
|
14
13
|
<ReduckMigration />
|
15
14
|
|
@@ -22,8 +21,8 @@ Reduck 在 MVC 模式中,扮演 M(Model) 的角色,React UI Component 对应
|
|
22
21
|
Modern.js 的状态管理解决方案,是通过内置 Reduck 实现的。在 Modern.js 中使用 Reduck,不仅免去了手动集成的环节,而且所有 Reduck API 都可以从 Modern.js 的 Runtime 包中直接导入使用,具有更好的一致性体验。
|
23
22
|
|
24
23
|
:::info
|
25
|
-
|
26
|
-
|
24
|
+
|
25
|
+
Reduck 也可以脱离 Modern.js 作为状态管理库[单独使用](/guides/topic-detail/model/use-out-of-modernjs)。
|
27
26
|
|
28
27
|
:::
|
29
28
|
|
@@ -1,7 +1,3 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 11
|
3
|
-
title: Redux 生态集成
|
4
|
-
---
|
5
1
|
# Redux 生态集成
|
6
2
|
|
7
3
|
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 的创建过程。
|
package/package.json
CHANGED
@@ -1,49 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: enableFrameworkExt
|
3
|
-
---
|
4
|
-
|
5
|
-
# server.enableFrameworkExt
|
6
|
-
|
7
|
-
- **Type:** `boolean`
|
8
|
-
- **Default:** `false`
|
9
|
-
|
10
|
-
By default, when the [custom Web Server feature](/guides/advanced-features/web-server) is enabled, the Middleware will use the Modern.js's syntax.
|
11
|
-
|
12
|
-
Enabling `server.enableFrameworkExt` allows the use of syntax extensions from other frameworks.
|
13
|
-
|
14
|
-
```ts title="modern.config.ts"
|
15
|
-
export default defineConfig({
|
16
|
-
server: {
|
17
|
-
enableFrameworkExt: true,
|
18
|
-
},
|
19
|
-
});
|
20
|
-
```
|
21
|
-
|
22
|
-
## Example
|
23
|
-
|
24
|
-
Default usage:
|
25
|
-
|
26
|
-
```ts title="server/index.ts"
|
27
|
-
import { Middleware } from '@modern-js/runtime/server';
|
28
|
-
|
29
|
-
export const middleware: Middleware = (ctx, next) => {
|
30
|
-
console.log(ctx.request.url);
|
31
|
-
next();
|
32
|
-
};
|
33
|
-
```
|
34
|
-
|
35
|
-
After enabling it, the Middleware type will be exported from other namespaces, and syntax extensions from frameworks can be used:
|
36
|
-
|
37
|
-
```ts title="server/index.ts"
|
38
|
-
import { SomeType } from '@modern-js/runtime/{namespace}';
|
39
|
-
|
40
|
-
export const middleware: SomeType = (...args) => {
|
41
|
-
console.log(args[0].url);
|
42
|
-
next();
|
43
|
-
};
|
44
|
-
```
|
45
|
-
|
46
|
-
:::note
|
47
|
-
The above code is pseudocode, and the specific usage needs to refer to the corresponding framework extension.
|
48
|
-
|
49
|
-
:::
|
@@ -1,49 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: enableFrameworkExt
|
3
|
-
---
|
4
|
-
|
5
|
-
# server.enableFrameworkExt
|
6
|
-
|
7
|
-
- **类型:** `boolean`
|
8
|
-
- **默认值:** `false`
|
9
|
-
|
10
|
-
默认情况下,开启[自定义 Web Server 功能](/guides/advanced-features/web-server)后,Middleware 会使用 Modern.js 本身的语法。
|
11
|
-
|
12
|
-
开启 `server.enableFrameworkExt` 可以使用其他框架扩展的语法。
|
13
|
-
|
14
|
-
```ts title="modern.config.ts"
|
15
|
-
export default defineConfig({
|
16
|
-
server: {
|
17
|
-
enableFrameworkExt: true,
|
18
|
-
},
|
19
|
-
});
|
20
|
-
```
|
21
|
-
|
22
|
-
## 示例
|
23
|
-
|
24
|
-
默认的使用方式:
|
25
|
-
|
26
|
-
```ts title="server/index.ts"
|
27
|
-
import { Middleware } from '@modern-js/runtime/server';
|
28
|
-
|
29
|
-
export const middleware: Middleware = (ctx, next) => {
|
30
|
-
console.log(ctx.request.url);
|
31
|
-
next();
|
32
|
-
};
|
33
|
-
```
|
34
|
-
|
35
|
-
开启后,Middleware 类型将从其他命名空间下导出,并且可以使用框架拓展的语法:
|
36
|
-
|
37
|
-
```ts title="server/index.ts"
|
38
|
-
import { SomeType } from '@modern-js/runtime/{namespace}';
|
39
|
-
|
40
|
-
export const middleware: SomeType = (...args) => {
|
41
|
-
console.log(args[0].url);
|
42
|
-
next();
|
43
|
-
};
|
44
|
-
```
|
45
|
-
|
46
|
-
:::note
|
47
|
-
上述代码为伪代码,具体使用方式需要参考对应的框架拓展。
|
48
|
-
|
49
|
-
:::
|