aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/main.browser.ts
blob: 28f0d57814b524f89506b5832d7e42d08a39d694 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* tslint: disable */

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { decorateModuleRef } from './app/environment'
import { hmrModule } from '@angularclass/hmr'

/**
 * App Module
 * our top level module that holds all of our components
 */
import { AppModule } from './app'

/**
 * Bootstrap our Angular app with a top level NgModule
 */
export function main (): Promise<any> {
  return platformBrowserDynamic()
    .bootstrapModule(AppModule)
    .then(decorateModuleRef)
    .then((ngModuleRef: any) => {
      // `module` global ref for webpackhmr
      // Don't run this in Prod
      return hmrModule(ngModuleRef, module)
    })
    .catch((err) => console.error(err))
}

/**
 * Needed for hmr
 * in prod this is replace for document ready
 */
switch (document.readyState) {
  case 'loading':
    document.addEventListener('DOMContentLoaded', _domReadyHandler, false)
    break
  case 'interactive':
  case 'complete':
  default:
    main()
}

function _domReadyHandler () {
  document.removeEventListener('DOMContentLoaded', _domReadyHandler, false)
  main()
}