]>
Commit | Line | Data |
---|---|---|
23bcf666 | 1 | import { ApplicationRef, NgModule } from '@angular/core'; |
ab32b0fc C |
2 | import { BrowserModule } from '@angular/platform-browser'; |
3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | |
4 | import { HttpModule, RequestOptions, XHRBackend } from '@angular/http'; | |
5 | import { RouterModule } from '@angular/router'; | |
6 | import { removeNgStyles, createNewHosts } from '@angularclass/hmr'; | |
7 | ||
23bcf666 | 8 | import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; |
2ac6c525 | 9 | import { DropdownModule } from 'ng2-bootstrap/components/dropdown'; |
ab32b0fc C |
10 | import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar'; |
11 | import { PaginationModule } from 'ng2-bootstrap/components/pagination'; | |
c53d2a4e | 12 | import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; |
ab32b0fc C |
13 | |
14 | /* | |
15 | * Platform and Environment providers/directives/pipes | |
16 | */ | |
17 | import { ENV_PROVIDERS } from './environment'; | |
18 | import { routes } from './app.routes'; | |
19 | // App is our top level component | |
20 | import { AppComponent } from './app.component'; | |
21 | import { AppState } from './app.service'; | |
23bcf666 C |
22 | |
23 | import { | |
24 | AdminComponent, | |
25 | FriendsComponent, | |
26 | FriendAddComponent, | |
27 | FriendListComponent, | |
28 | FriendService, | |
29 | MenuAdminComponent, | |
eb4f957e C |
30 | RequestsComponent, |
31 | RequestStatsComponent, | |
32 | RequestService, | |
23bcf666 C |
33 | UsersComponent, |
34 | UserAddComponent, | |
35 | UserListComponent, | |
36 | UserService | |
37 | } from './admin'; | |
ab32b0fc C |
38 | import { AccountComponent, AccountService } from './account'; |
39 | import { LoginComponent } from './login'; | |
23bcf666 C |
40 | import { MenuComponent } from './menu.component'; |
41 | import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared'; | |
ab32b0fc C |
42 | import { |
43 | LoaderComponent, | |
44 | VideosComponent, | |
45 | VideoAddComponent, | |
46 | VideoListComponent, | |
47 | VideoMiniatureComponent, | |
48 | VideoSortComponent, | |
49 | VideoWatchComponent, | |
4b2f33f3 C |
50 | VideoService, |
51 | WebTorrentService | |
ab32b0fc | 52 | } from './videos'; |
ab32b0fc C |
53 | |
54 | // Application wide providers | |
55 | const APP_PROVIDERS = [ | |
56 | AppState, | |
57 | ||
58 | { | |
59 | provide: AuthHttp, | |
60 | useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => { | |
61 | return new AuthHttp(backend, defaultOptions, authService); | |
62 | }, | |
63 | deps: [ XHRBackend, RequestOptions, AuthService ] | |
64 | }, | |
65 | ||
66 | AuthService, | |
67 | RestExtractor, | |
23bcf666 C |
68 | RestService, |
69 | ||
70 | VideoService, | |
71 | SearchService, | |
72 | FriendService, | |
eb4f957e | 73 | RequestService, |
23bcf666 C |
74 | UserService, |
75 | AccountService, | |
76 | WebTorrentService | |
ab32b0fc C |
77 | ]; |
78 | /** | |
79 | * `AppModule` is the main entry point into Angular2's bootstraping process | |
80 | */ | |
81 | @NgModule({ | |
82 | bootstrap: [ AppComponent ], | |
83 | declarations: [ | |
23bcf666 C |
84 | AccountComponent, |
85 | AdminComponent, | |
ab32b0fc C |
86 | AppComponent, |
87 | BytesPipe, | |
23bcf666 C |
88 | FriendAddComponent, |
89 | FriendListComponent, | |
90 | FriendsComponent, | |
ab32b0fc | 91 | LoaderComponent, |
23bcf666 C |
92 | LoginComponent, |
93 | MenuAdminComponent, | |
94 | MenuComponent, | |
eb4f957e C |
95 | RequestsComponent, |
96 | RequestStatsComponent, | |
23bcf666 C |
97 | SearchComponent, |
98 | UserAddComponent, | |
99 | UserListComponent, | |
100 | UsersComponent, | |
ab32b0fc C |
101 | VideoAddComponent, |
102 | VideoListComponent, | |
ab32b0fc | 103 | VideoMiniatureComponent, |
23bcf666 C |
104 | VideosComponent, |
105 | VideoSortComponent, | |
ab32b0fc | 106 | VideoWatchComponent, |
ab32b0fc C |
107 | ], |
108 | imports: [ // import Angular's modules | |
109 | BrowserModule, | |
110 | FormsModule, | |
111 | ReactiveFormsModule, | |
112 | HttpModule, | |
113 | RouterModule.forRoot(routes), | |
23bcf666 | 114 | |
2ac6c525 | 115 | DropdownModule, |
ab32b0fc | 116 | ProgressbarModule, |
c53d2a4e C |
117 | PaginationModule, |
118 | FileUploadModule | |
ab32b0fc C |
119 | ], |
120 | providers: [ // expose our Services and Providers into Angular's dependency injection | |
121 | ENV_PROVIDERS, | |
122 | APP_PROVIDERS | |
123 | ] | |
124 | }) | |
125 | export class AppModule { | |
126 | constructor(public appRef: ApplicationRef, public appState: AppState) {} | |
127 | hmrOnInit(store) { | |
128 | if (!store || !store.state) return; | |
129 | console.log('HMR store', store); | |
130 | this.appState._state = store.state; | |
131 | this.appRef.tick(); | |
132 | delete store.state; | |
133 | } | |
134 | hmrOnDestroy(store) { | |
135 | const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement); | |
136 | // recreate elements | |
137 | const state = this.appState._state; | |
138 | store.state = state; | |
139 | store.disposeOldHosts = createNewHosts(cmpLocation); | |
140 | // remove styles | |
141 | removeNgStyles(); | |
142 | } | |
143 | hmrAfterDestroy(store) { | |
144 | // display new elements | |
145 | store.disposeOldHosts(); | |
146 | delete store.disposeOldHosts; | |
147 | } | |
148 | } |