不管前端框架是用 ReactJS,还是 VueJS,最终渲染到浏览器上的都是 Dom 对象,一颗 Dom 树。而 ApplicationShell 接口正是对不同前端框架挂载到真正的 Dom 树上的一个抽象。
接口定义
export interface ApplicationShell {attach(host: HTMLElement): void; // host 是前端应用真正要挂载到的 Dom 对象}
简单实现
以下是框架默认的简单实现,真实场景应该需要替换掉默认实现:
@Component(ApplicationShell)export class ApplicationShellImpl implements ApplicationShell {attach(host: HTMLElement): void {host.textContent = 'Hello, Malagu.';}}
ReactJS 实现
需要替换掉框架默认的简单实现:
@Component({ id: ApplicationShell, rebind: true })export class Shell implements ApplicationShell {attach(host: HTMLElement): void {ReactDOM.render(<App/>, host);}}
