-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
feat: support lifecycyle hooks in module-deferation bridge #2992
base: main
Are you sure you want to change the base?
Changes from all commits
3118053
3082116
f716f18
edaffa2
62480b6
c868988
cf83897
aa05fc5
8aebc66
e414ded
f575ec7
fe9ad08
7257784
74f057a
14a30fa
b47ea80
b02d9f0
93627d9
5e33da2
83e54ad
2fac2ea
4e319bb
a891716
5c7f0be
a6c9c97
10bc78b
19acf8b
25d850b
8588609
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@module-federation/bridge-react': patch | ||
'@module-federation/bridge-vue3': patch | ||
'@module-federation/runtime': patch | ||
--- | ||
|
||
feat: support module isolated reported |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { getInstance } from '@module-federation/runtime'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import helper from '@module-federation/runtime/helpers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
function registerBridgeLifeCycle() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const { registerPlugins, pluginHelper } = helper.global; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const host = getInstance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const pluginSystem = new pluginHelper.PluginSystem({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
beforeBridgeRender: new pluginHelper.SyncHook<[Record<string, any>], any>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
afterBridgeRender: new pluginHelper.SyncHook<[Record<string, any>], any>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
beforeBridgeDestroy: new pluginHelper.SyncHook< | ||||||||||||||||||||||||||||||||||||||||||||||||||||
[Record<string, any>], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
any | ||||||||||||||||||||||||||||||||||||||||||||||||||||
>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
afterBridgeDestroy: new pluginHelper.SyncHook<[Record<string, any>], any>(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+5
to
+15
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. The code introduces a plugin system with lifecycle hooks for a bridge component. While the implementation looks good, there are a few suggestions to improve type safety and readability:
Here's an example of how you could improve the code:
Suggested change
This change improves type safety and makes the code more concise and easier to maintain. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
if (host) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
registerPlugins<typeof pluginSystem.lifecycle, typeof pluginSystem>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
host?.options?.plugins, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
[pluginSystem], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return pluginSystem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
export { registerBridgeLifeCycle }; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,25 +2,37 @@ import { useLayoutEffect, useRef, useState } from 'react'; | |||||||||
import * as React from 'react'; | ||||||||||
import ReactDOM from 'react-dom'; | ||||||||||
import ReactDOMClient from 'react-dom/client'; | ||||||||||
import { RouterContext } from './context'; | ||||||||||
import type { | ||||||||||
ProviderParams, | ||||||||||
RenderFnParams, | ||||||||||
} from '@module-federation/bridge-shared'; | ||||||||||
import { LoggerInstance, atLeastReact18 } from './utils'; | ||||||||||
import { ErrorBoundary } from 'react-error-boundary'; | ||||||||||
import { RouterContext } from './context'; | ||||||||||
import { LoggerInstance, atLeastReact18 } from './utils'; | ||||||||||
|
||||||||||
type RenderParams = RenderFnParams & any; | ||||||||||
type DestroyParams = { | ||||||||||
dom: HTMLElement; | ||||||||||
}; | ||||||||||
type RootType = HTMLElement | ReactDOMClient.Root; | ||||||||||
|
||||||||||
type BridgeHooks = { | ||||||||||
beforeBridgeRender?: (params: RenderFnParams) => any; | ||||||||||
afterBridgeRender?: (params: RenderFnParams) => any; | ||||||||||
beforeBridgeDestroy?: (params: DestroyParams) => any; | ||||||||||
afterBridgeDestroy?: (params: DestroyParams) => any; | ||||||||||
}; | ||||||||||
|
||||||||||
type ProviderFnParams<T> = { | ||||||||||
rootComponent: React.ComponentType<T>; | ||||||||||
render?: ( | ||||||||||
App: React.ReactElement, | ||||||||||
id?: HTMLElement | string, | ||||||||||
) => RootType | Promise<RootType>; | ||||||||||
hooks?: BridgeHooks; | ||||||||||
}; | ||||||||||
|
||||||||||
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) { | ||||||||||
return () => { | ||||||||||
return (params: { hooks?: BridgeHooks }) => { | ||||||||||
const rootMap = new Map<any, RootType>(); | ||||||||||
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => { | ||||||||||
const { appInfo, propsInfo, ...restProps } = info; | ||||||||||
|
@@ -37,7 +49,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) { | |||||||||
}; | ||||||||||
|
||||||||||
return { | ||||||||||
async render(info: RenderFnParams & any) { | ||||||||||
async render(info: RenderParams) { | ||||||||||
LoggerInstance.log(`createBridgeComponent render Info`, info); | ||||||||||
const { | ||||||||||
moduleName, | ||||||||||
|
@@ -47,6 +59,21 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) { | |||||||||
fallback, | ||||||||||
...propsInfo | ||||||||||
} = info; | ||||||||||
|
||||||||||
const beforeBridgeRender = | ||||||||||
(bridgeInfo?.hooks && bridgeInfo?.hooks.beforeBridgeRender) || | ||||||||||
params?.hooks?.beforeBridgeRender; | ||||||||||
Comment on lines
+63
to
+65
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. The code for retrieving
Suggested change
This change improves readability and reduces the chance of errors. |
||||||||||
|
||||||||||
// 可通过beforeBridgeRender返回一个props对象,用于传递额外的 props 参数 | ||||||||||
const beforeBridgeRenderRes = | ||||||||||
beforeBridgeRender && beforeBridgeRender(info); | ||||||||||
const extraProps = | ||||||||||
beforeBridgeRenderRes && | ||||||||||
typeof beforeBridgeRenderRes === 'object' && | ||||||||||
beforeBridgeRenderRes?.extraProps | ||||||||||
? beforeBridgeRenderRes?.extraProps | ||||||||||
: {}; | ||||||||||
|
||||||||||
const rootComponentWithErrorBoundary = ( | ||||||||||
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error | ||||||||||
<ErrorBoundary FallbackComponent={fallback}> | ||||||||||
|
@@ -56,11 +83,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) { | |||||||||
basename, | ||||||||||
memoryRoute, | ||||||||||
}} | ||||||||||
propsInfo={propsInfo} | ||||||||||
propsInfo={{ ...propsInfo, ...extraProps } as T} | ||||||||||
/> | ||||||||||
</ErrorBoundary> | ||||||||||
); | ||||||||||
|
||||||||||
// call render function | ||||||||||
if (atLeastReact18(React)) { | ||||||||||
if (bridgeInfo?.render) { | ||||||||||
// in case bridgeInfo?.render is an async function, resolve this to promise | ||||||||||
|
@@ -77,18 +104,45 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) { | |||||||||
const renderFn = bridgeInfo?.render || ReactDOM.render; | ||||||||||
renderFn?.(rootComponentWithErrorBoundary, info.dom); | ||||||||||
} | ||||||||||
|
||||||||||
const afterBridgeRender = | ||||||||||
(bridgeInfo?.hooks && bridgeInfo?.hooks.afterBridgeDestroy) || | ||||||||||
params?.hooks?.afterBridgeRender; | ||||||||||
afterBridgeRender && afterBridgeRender(info); | ||||||||||
}, | ||||||||||
async destroy(info: { dom: HTMLElement }) { | ||||||||||
|
||||||||||
async destroy(info: DestroyParams) { | ||||||||||
LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||||||||||
dom: info.dom, | ||||||||||
}); | ||||||||||
|
||||||||||
// call beforeBridgeDestroy hook | ||||||||||
if ( | ||||||||||
bridgeInfo?.hooks && | ||||||||||
bridgeInfo?.hooks.beforeBridgeDestroy && | ||||||||||
typeof bridgeInfo?.hooks.beforeBridgeDestroy === 'function' | ||||||||||
) { | ||||||||||
bridgeInfo.hooks.beforeBridgeDestroy(info); | ||||||||||
} | ||||||||||
|
||||||||||
const beforeBridgeDestroy = | ||||||||||
(bridgeInfo?.hooks && bridgeInfo?.hooks.beforeBridgeDestroy) || | ||||||||||
params?.hooks?.beforeBridgeDestroy; | ||||||||||
beforeBridgeDestroy && beforeBridgeDestroy(info); | ||||||||||
|
||||||||||
// call destroy function | ||||||||||
if (atLeastReact18(React)) { | ||||||||||
const root = rootMap.get(info.dom); | ||||||||||
(root as ReactDOMClient.Root)?.unmount(); | ||||||||||
rootMap.delete(info.dom); | ||||||||||
} else { | ||||||||||
ReactDOM.unmountComponentAtNode(info.dom); | ||||||||||
} | ||||||||||
|
||||||||||
const afterBridgeDestroy = | ||||||||||
(bridgeInfo?.hooks && bridgeInfo?.hooks.afterBridgeDestroy) || | ||||||||||
params?.hooks?.afterBridgeDestroy; | ||||||||||
afterBridgeDestroy && afterBridgeDestroy(info); | ||||||||||
}, | ||||||||||
rawComponent: bridgeInfo.rootComponent, | ||||||||||
__BRIDGE_FN__: (_args: T) => {}, | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,9 +7,25 @@ import React, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
} from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import * as ReactRouterDOM from 'react-router-dom'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import type { ProviderParams } from '@module-federation/bridge-shared'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { LoggerInstance, pathJoin } from '../utils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { dispatchPopstateEnv } from '@module-federation/bridge-shared'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { registerBridgeLifeCycle } from '../lifecycle'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { LoggerInstance, pathJoin } from '../utils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const getModuleName = (id: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// separate module name without detailed module path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const idArray = id.split('/'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (idArray.length < 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return idArray[0] + '/' + idArray[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const getRootDomDefaultClassName = (moduleName: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return `bridge-root-component-${name}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
declare const __APP_VERSION__: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export interface RenderFnParams extends ProviderParams { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -39,6 +55,7 @@ const RemoteAppWrapper = forwardRef(function ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
props: RemoteAppParams & RenderFnParams, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const bridgeHook = registerBridgeLifeCycle(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const RemoteApp = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -65,7 +82,7 @@ const RemoteAppWrapper = forwardRef(function ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
const providerReturn = providerInfo(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
providerInfoRef.current = providerReturn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const renderProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let renderProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
moduleName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dom: rootRef.current, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
basename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -78,6 +95,24 @@ const RemoteAppWrapper = forwardRef(function ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
`createRemoteComponent LazyComponent render >>>`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
renderProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (bridgeHook && bridgeHook?.lifecycle?.beforeBridgeRender) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const beforeBridgeRenderRes = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bridgeHook?.lifecycle?.beforeBridgeRender.emit({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...renderProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const extraProps = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
beforeBridgeRenderRes && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
typeof beforeBridgeRenderRes === 'object' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
beforeBridgeRenderRes?.extraProps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? beforeBridgeRenderRes?.extraProps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
: {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
renderProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...renderProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...extraProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} as any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Remove the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+99
to
+115
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. The lifecycle hook implementation can be simplified and made more robust:
Here's a suggested refactoring:
Suggested change
This change improves readability and reduces the chance of runtime errors. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
providerReturn.render(renderProps); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -89,6 +124,16 @@ const RemoteAppWrapper = forwardRef(function ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
`createRemoteComponent LazyComponent destroy >>>`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ moduleName, basename, dom: renderDom.current }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (bridgeHook && bridgeHook?.lifecycle?.afterBridgeDestroy) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bridgeHook?.lifecycle?.afterBridgeDestroy.emit({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
moduleName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dom: renderDom.current, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
basename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+127
to
+131
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. Similar to the
Suggested change
This change uses optional chaining to simplify the nested property access and improve readability. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
memoryRoute, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fallback, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...resProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
providerInfoRef.current?.destroy({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dom: renderDom.current, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -97,9 +142,11 @@ const RemoteAppWrapper = forwardRef(function ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// bridge-remote-root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
className={props?.className} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
className={rootComponentClassName} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style={props?.style} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ref={rootRef} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
></div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getInstance } from '@module-federation/runtime'; | ||
import helper from '@module-federation/runtime/helpers'; | ||
|
||
function registerBridgeLifeCycle() { | ||
const { registerPlugins, pluginHelper } = helper.global; | ||
const host = getInstance(); | ||
const pluginSystem = new pluginHelper.PluginSystem({ | ||
beforeBridgeRender: new pluginHelper.SyncHook< | ||
[Record<string, any>], | ||
void | ||
>(), | ||
beforeBridgeDestroy: new pluginHelper.SyncHook< | ||
[Record<string, any>], | ||
void | ||
>(), | ||
}); | ||
|
||
if (host) { | ||
registerPlugins<typeof pluginSystem.lifecycle, typeof pluginSystem>( | ||
host?.options?.plugins, | ||
[pluginSystem], | ||
); | ||
return pluginSystem; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export { registerBridgeLifeCycle }; |
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.
i wonder if we should make this use named exports in the future, so that better tree shake or destructure is possible later. (for the helpers stuff)
import {global} from helper