import { InDiv , IPlugin , utils , ErrorHandler } from '@indiv/core' ; import { getService , rootInjector } from '@indiv/di' ; import { PlatfromBrowserRenderer } from '../renderer' ; export class implements IPlugin export class PlatformBrowser implements IPlugin { public bootstrap ( application ) { application . setIndivEnv ( 'browser' , false ) ; application . setRootElement ( document . getElementById ( 'root' ) ) ; application . setRenderer ( PlatfromBrowserRenderer ) ; if ( utils . hasWindowAndDocument ( ) ) { let errorHandler = null ; const rootElement = application . getRootElement ; if ( ! rootElement ) return ; rootElement . addEventListener ( 'error' , ( ev ) => { if ( ! errorHandler && application . getRootModule ) { const injector = application . getRootModule . $privateInjector || rootInjector ; if ( ! injector . getProvider ( ErrorHandler ) ) return ; errorHandler = getService ( injector , ErrorHandler ) ; } if ( errorHandler ) errorHandler . handleError ( ev ) ; } , true ) ; rootElement . addEventListener ( "unhandledrejection" , ( ev ) => { if ( ! errorHandler && application . getRootModule ) { const injector = application . getRootModule . $privateInjector || rootInjector ; if ( ! injector . getProvider ( ErrorHandler ) ) return ; errorHandler = getService ( injector , ErrorHandler ) ; } if ( errorHandler ) errorHandler . handleError ( ev ) ; } , true ) ; } } }