Skip to content

Commit 7d41a71

Browse files
authored
Merge branch 'main' into refactor/type-schema
2 parents e580ead + 4466f4c commit 7d41a71

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

apps/website-new/docs/en/guide/runtime/runtime-api.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ Used to create ModuleFederation instance.
1212

1313
* When to use `createInstance`?
1414

15-
To ensure the uniqueness of the ModuleFederation instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the ModuleFederation instance from memory and then call the APIs of the ModuleFederation instance. This is also why APIs like loadRemote can be used directly from the `@module-federation/enhanced/runtime` package and inherently understand what application container they are attached to.
15+
To ensure the uniqueness of the ModuleFederation instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the ModuleFederation instance from memory and then call the APIs of the ModuleFederation instance. This is also why APIs like loadRemote can be used directly from the `@module-federation/enhanced/runtime` package and inherently understand what application container they are attached to.
1616

17-
This singleton pattern works for most scenarios, but in the following cases, you need to use `createInstance`:
17+
This singleton pattern works for most scenarios, but in the following cases, you need to use `createInstance`:
1818

19-
- No build plugin is used (Only use runtime)
20-
- Multiple ModuleFederation instances need to be created with different configurations for each instance
21-
- You want to use ModuleFederation's partitioning feature to encapsulate corresponding APIs for use in other projects
19+
- No build plugin is used (Only use runtime)
20+
- Multiple ModuleFederation instances need to be created with different configurations for each instance
21+
- You want to use ModuleFederation's partitioning feature to encapsulate corresponding APIs for use in other projects
22+
23+
* `createInstance` will not overwrite an existing instance. Each call will create a new instance.
2224

2325
```ts
2426
import { createInstance } from '@module-federation/enhanced/runtime';

apps/website-new/docs/zh/guide/runtime/runtime-api.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import Runtime from '@components/zh/runtime/index';
1212

1313
* 什么时候使用 `createInstance`
1414

15-
为了保证 `ModuleFederation` 实例的唯一性,我们在构建插件创建实例后,会将其存储到内存中,导出的 API 都是先从内存中获取 `ModuleFederation` 实例,然后再调用 `ModuleFederation` 实例的 API。这也是为什么 `loadRemote` 等 API 可以直接使用的原因。
15+
为了保证 `ModuleFederation` 实例的唯一性,我们在构建插件创建实例后,会将其存储到内存中,导出的 API 都是先从内存中获取 `ModuleFederation` 实例,然后再调用 `ModuleFederation` 实例的 API。这也是为什么 `loadRemote` 等 API 可以直接使用的原因。
1616

17-
这种单例模式适用于大多数场景,但如果在以下场景,你需要使用 `createInstance`
17+
这种单例模式适用于大多数场景,但如果在以下场景,你需要使用 `createInstance`
1818

19-
- 没有使用构建插件(纯运行时场景)
20-
- 需要创建多个 ModuleFederation 实例,每个实例的配置不同
21-
- 希望使用 ModuleFederation 分治特性,封装相应的 API 提供给其他项目使用
19+
- 没有使用构建插件(纯运行时场景)
20+
- 需要创建多个 ModuleFederation 实例,每个实例的配置不同
21+
- 希望使用 ModuleFederation 分治特性,封装相应的 API 提供给其他项目使用
22+
23+
24+
* `createInstance` 不会对已存在的实例进行覆盖,每次调用都会创建一个新的实例。
2225

2326
```ts
2427
import { createInstance } from '@module-federation/enhanced/runtime';

0 commit comments

Comments
 (0)