You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/basic/runtime/runtime-api.mdx
+32-31Lines changed: 32 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -3,49 +3,49 @@
3
3
import { Badge } from'@theme';
4
4
importCollapsefrom'@components/Collapse'
5
5
6
-
If the build plugin is used, an MF instance will be automatically created and stored in memory when the project starts. You can directly call methods of the MF instance via the <Badge>API</Badge>.
6
+
If the build plugin is used, an MF instance will be automatically created and stored in memory when the project starts. You can directly call methods of the MF instance via the .
7
7
8
8
If the build plugin is not used, you need to manually create an MF instance before calling the corresponding API.
In addition to exposing APIs, the Runtime also provides the ModuleFederation class, which you can use to create ModuleFederation instance.
13
-
14
10
* What is a `ModuleFederation` instance?
15
11
16
12
A `ModuleFederation` instance is an instance of the `ModuleFederation` class, which contains all the functionality of the `ModuleFederation` runtime.
17
13
18
14
> You can enter `__FEDERATION__.__INSTANCES__` in the console to view the created instances.
19
15
20
-
* When to use `ModuleFederation` class?
16
+
## createInstance
17
+
18
+
In addition to exposing APIs, the Runtime also provides the `createInstance`, which you can use to create ModuleFederation instance.
19
+
20
+
* When to use `createInstance`?
21
21
22
22
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.
23
23
24
-
However, this singleton pattern also limits the ability to create multiple instances, as it assumes that there is only one instance per bundle. Therefore, if you need to create a new instance , you can use the ModuleFederation class to create a new one.
24
+
However, this singleton pattern also limits the ability to create multiple instances, as it assumes that there is only one instance per bundle. Therefore, if you need to create a new instance , you can use the [createInstance](#createinstance) to create a new one.
If the build plugin is not used, calling `getInstance` will throw an exception. In this case, you need to use the [ModuleFederation](#modulefederation) class to create a new instance.
155
+
If the build plugin is not used, calling `getInstance` will throw an exception. In this case, you need to use the [createInstance](#createinstance) to create a new instance.
- Gets a `share` dependency. When there is a `share` dependency in the global environment that meets the requirements of the current `host`, the existing dependency that meets the `share` conditions will be reused first. Otherwise, its own dependency will be loaded and stored in the global cache.
@@ -426,7 +427,7 @@ loadShare('react', {
426
427
});
427
428
```
428
429
429
-
## preloadRemote <Badge>API</Badge>
430
+
## preloadRemote
430
431
431
432
<Collapse>
432
433
@@ -486,9 +487,9 @@ registerRemotes([
486
487
},
487
488
]);
488
489
489
-
// Preload the @demo/sub1 module
490
+
// Preload the sub1 module
490
491
// Filter resource information that contains 'ignore' in the resource name
491
-
// Only preload the sub-dependency @demo/sub1-button module
492
+
// Only preload the sub-dependency sub1-button module
492
493
preloadRemote([
493
494
{
494
495
nameOrAlias: 'sub1',
@@ -500,17 +501,17 @@ preloadRemote([
500
501
]);
501
502
502
503
503
-
// Preload the @demo/sub2 module
504
-
// Preload all exposes under @demo/sub2
505
-
// Preload the synchronous and asynchronous resources of @demo/sub2
504
+
// Preload the sub2 module
505
+
// Preload all exposes under sub2
506
+
// Preload the synchronous and asynchronous resources of sub2
506
507
preloadRemote([
507
508
{
508
509
nameOrAlias: 'sub2',
509
510
resourceCategory: 'all',
510
511
},
511
512
]);
512
513
513
-
// Preload the add expose of the @demo/sub3 module
0 commit comments