-
Notifications
You must be signed in to change notification settings - Fork 4
API Reference Common
Package:
@microfrontend/commonVersion: 1.6.0 Install:npm install @microfrontend/commonNo peer dependencies
This package is installed in both the shell and every microfrontend. It provides the shared messaging protocol, base classes, and infrastructure.
Logging level for controlling console output verbosity.
import { Level } from '@microfrontend/common';| Value | Numeric | Description |
|---|---|---|
OFF |
0 | No logging |
ERROR |
1 | Errors only |
WARNING |
2 | Errors and warnings |
INFO |
3 | General information (default) |
DEBUG |
4 | Debug-level detail |
LOG |
5 | Maximum verbosity |
Message broker that translates window.postMessage events into typed handler callbacks. Validates message origins against a whitelist before dispatching.
import { MessagingApiBroker } from '@microfrontend/common';This class is used internally by MetaRouter and RoutedApp. You typically do not instantiate it directly.
- Listens for
messageevents on the window - Validates each message's
originagainst theallowedOriginswhitelist - Dispatches typed messages to registered handler callbacks
- Extends
Destroyablefor lifecycle management
Base class providing lifecycle management with a destruction guard pattern.
import { Destroyable } from '@microfrontend/common';| Method | Return | Description |
|---|---|---|
destroy() |
void |
Marks the object as destroyed. Throws if already destroyed. |
isDestroyed() |
boolean |
Returns true if destroy() has been called |
preventUsageUponDestruction() |
void |
Throws Error if the object has been destroyed |
import { IDestroyable } from '@microfrontend/common';| Method | Return | Description |
|---|---|---|
destroy() |
void |
Destroy the object |
isDestroyed() |
boolean |
Check if destroyed |
All messages extend MessageBase and are transmitted via window.postMessage between the shell and microfrontends.
Base interface for all messages.
| Property | Type | Description |
|---|---|---|
message |
string |
Message type identifier |
source |
string |
Sender's meta route name (or shell name) |
Sent by a microfrontend to report its current route to the shell.
| Property | Type | Description |
|---|---|---|
message |
'routed' |
— |
source |
string |
Microfrontend's meta route |
subRoute |
string |
Current subroute URL |
Sent by the shell to tell a microfrontend it has been activated.
| Property | Type | Description |
|---|---|---|
message |
'meta-routed' |
— |
source |
string |
Shell name |
activated |
boolean |
Whether the microfrontend is being activated |
subRoute |
string | undefined |
Subroute to navigate to |
Sent by a microfrontend to request navigation to another microfrontend.
| Property | Type | Description |
|---|---|---|
message |
'goto' |
— |
source |
string |
Sender's meta route |
metaRoute |
string |
Target meta route |
subRoute |
string | undefined |
Target subroute |
Broadcast message sent between microfrontends (routed through the shell).
| Property | Type | Description |
|---|---|---|
message |
'broadcast' |
— |
metadata |
MessageBroadcastMetadata |
Broadcast metadata |
data |
object |
Payload |
Metadata accompanying a broadcast message.
| Property | Type | Description |
|---|---|---|
tag |
string |
Message tag/type |
source |
string |
Sender's meta route |
recipients |
string[] | undefined |
Target meta routes (all if omitted) |
isRecipientVisible |
boolean | undefined |
Whether the receiving microfrontend is currently visible |
Sent by a microfrontend to request iframe style changes.
| Property | Type | Description |
|---|---|---|
message |
'setFrameStyles' |
— |
source |
string |
Microfrontend's meta route |
styles |
IMap<string> |
CSS styles to apply to the iframe |
Sent as both a request (microfrontend to shell) and a response (shell to microfrontend) for custom iframe configuration data.
| Property | Type | Description |
|---|---|---|
message |
'getCustomFrameConfiguration' |
— |
source |
string |
Sender |
configuration |
IMap<string> |
Configuration key-value pairs |
Sent by a microfrontend to report dirty state.
| Property | Type | Description |
|---|---|---|
message |
'stateChanged' |
— |
source |
string |
Microfrontend's meta route |
hasState |
boolean |
Whether the microfrontend has unsaved state |
subRoute |
string | undefined |
Subroute with the state |
Sent by the shell to tell a microfrontend to discard its state.
| Property | Type | Description |
|---|---|---|
message |
'stateDiscard' |
— |
source |
string |
Shell name |
metaRoute |
string |
Target meta route |
subRoute |
string | undefined |
Target subroute |
Notification that a microfrontend has finished loading.
| Property | Type | Description |
|---|---|---|
message |
'microfrontendLoaded' |
— |
metaRoute |
string |
Loaded microfrontend's meta route |
Generic string-keyed dictionary interface used throughout the library.
import { IMap } from '@microfrontend/common';interface IMap<T> {
[key: string]: T;
}Interface for structured logging.
import { IConsoleFacade } from '@microfrontend/common';| Method | Description |
|---|---|
error(message, ...params) |
Log an error |
warning(message, ...params) |
Log a warning |
info(message, ...params) |
Log information |
debug(message, ...params) |
Log debug information |
log(message, ...params) |
Log at max verbosity |
type HandleBroadcastNotification = (metadata: MessageBroadcastMetadata, data: object) => void;type HandleGetCustomFrameConfiguration = (configuration: IMap<string>) => void;@microfrontend — MIT License — npm — GitHub
Getting Started
Guides
API Reference
Contributing