import singleSpaAngular from 'single-spa-angular' ; import { EventEmitter } from '@alicloud/console-os-events' ; interface BootstrapOptions { NgZone : any ; bootstrapFunction ( props ) : Promise < any > ; template : string ; Router ? : any ; domElementGetter ? ( ) : HTMLElement ; AnimationEngine ? : any ; } const globalEventEmitter = ( data ) => { window . postMessage ( data . data , null ) ; } ; const bindEvents = ( emitter ) => { emitter && emitter . on ( 'main:postMessage' , globalEventEmitter ) ; } ; const unbindEvents = ( emitter ) => { emitter && emitter . off ( 'main:postMessage' , globalEventEmitter ) ; } ; const getProps = ( props ) => { const appProps = { ... props , ... ( props . appProps || { } ) } ; delete appProps . singleSpa ; delete appProps . mountParcel ; return appProps || { } ; } ; export const bootstrap = ( options ) => { if ( window . __IS_CONSOLE_OS_CONTEXT__ ) { const lifecycles = singleSpaAngular ( options ) ; return { bootstrap : [ lifecycles . bootstrap ] , mount : [ ( props ) => { const { emitter } = getProps ( props ) ; bindEvents ( emitter ) ; return lifecycles . mount ( props ) ; } ] , unmount : [ ( props ) => { const { emitter } = getProps ( props ) ; unbindEvents ( emitter ) ; return lifecycles . unmount ( props ) ; } ] , update : [ ] } ; } else { return options . bootstrapFunction ( { } ) ; } } ;