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