-
-
Notifications
You must be signed in to change notification settings - Fork 335
docs: add FederationHost class usage description #3827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -449,6 +449,31 @@ registerPlugins([runtimePlugin()]); | |||||
|
||||||
If you want to develop Module Federation plugin, you can read [Module Federation Plugin System](../../plugin/dev/index) for more info. | ||||||
|
||||||
## FederationHost | ||||||
|
||||||
In addition to exposing APIs, Federation Runtime also provides the FederationHost class, which you can use to create a FederationHost instance. | ||||||
|
||||||
* When to use `FederationHost` ? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be a good idea to have small section on "What is FederationHost" How i explained it to people before was that in the FEDERATION.INSTANCES - each runtime or application who uses module federation creates a FederationHost instance, it represents an both consumer and provider instances of the system. Or something so users understand what federation host actually is for |
||||||
|
||||||
To ensure the uniqueness of the FederationHost instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the FederationHost instance from memory and then call the APIs of the FederationHost instance. This is also why APIs like loadRemote can be used directly. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
However, this singleton pattern also limits the inability to create multiple instances. Therefore, if you need to create a new instance , you can use the FederationHost class to create a new one. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```ts | ||||||
import { FederationHost } from '@module-federation/enhanced/runtime'; | ||||||
|
||||||
const host = new FederationHost({ | ||||||
name: '@demo/host', | ||||||
remotes: [ | ||||||
{ | ||||||
name: '@demo/sub1', | ||||||
entry: 'http://localhost:8080/mf-manifest.json' | ||||||
} | ||||||
] | ||||||
}); | ||||||
|
||||||
host.loadRemote('@demo/sub1/util').then((m) => m.add(1, 2, 3)); | ||||||
``` | ||||||
|
||||||
## FAQ | ||||||
|
||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.