@@ -6,16 +6,16 @@ import "./polyfills/array";
6
6
import "./polyfills/console" ;
7
7
8
8
import {
9
- Type ,
10
- Injector ,
11
- CompilerOptions ,
12
- PlatformRef ,
13
- NgModuleFactory ,
14
- NgModuleRef ,
15
- EventEmitter ,
16
- Provider ,
17
- Sanitizer ,
18
- OpaqueToken ,
9
+ Type ,
10
+ Injector ,
11
+ CompilerOptions ,
12
+ PlatformRef ,
13
+ NgModuleFactory ,
14
+ NgModuleRef ,
15
+ EventEmitter ,
16
+ Provider ,
17
+ Sanitizer ,
18
+ OpaqueToken ,
19
19
} from "@angular/core" ;
20
20
21
21
// Work around a TS bug requiring an import of OpaqueToken without using it
@@ -42,158 +42,164 @@ let lastBootstrappedModule: WeakRef<NgModuleRef<any>>;
42
42
type BootstrapperAction = ( ) => Promise < NgModuleRef < any > > ;
43
43
44
44
export interface AppOptions {
45
- bootInExistingPage : boolean ;
46
- cssFile ?: string ;
47
- startPageActionBarHidden ?: boolean ;
45
+ bootInExistingPage ? : boolean ;
46
+ cssFile ?: string ;
47
+ startPageActionBarHidden ?: boolean ;
48
48
}
49
49
50
50
export type PlatformFactory = ( extraProviders ?: Provider [ ] ) => PlatformRef ;
51
51
52
52
export class NativeScriptSanitizer extends Sanitizer {
53
- sanitize ( _context : any , value : string ) : string {
54
- return value ;
55
- }
53
+ sanitize ( _context : any , value : string ) : string {
54
+ return value ;
55
+ }
56
56
}
57
57
58
58
export const COMMON_PROVIDERS = [
59
- defaultPageFactoryProvider ,
60
- { provide : Sanitizer , useClass : NativeScriptSanitizer } ,
59
+ defaultPageFactoryProvider ,
60
+ { provide : Sanitizer , useClass : NativeScriptSanitizer } ,
61
61
] ;
62
62
63
63
export class NativeScriptPlatformRef extends PlatformRef {
64
- private _bootstrapper : BootstrapperAction ;
64
+ private _bootstrapper : BootstrapperAction ;
65
65
66
- constructor ( private platform : PlatformRef , private appOptions ?: AppOptions ) {
67
- super ( ) ;
68
- }
66
+ constructor ( private platform : PlatformRef , private appOptions ?: AppOptions ) {
67
+ super ( ) ;
68
+ }
69
69
70
- bootstrapModuleFactory < M > ( moduleFactory : NgModuleFactory < M > ) : Promise < NgModuleRef < M > > {
71
- this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory ( moduleFactory ) ;
70
+ bootstrapModuleFactory < M > ( moduleFactory : NgModuleFactory < M > ) : Promise < NgModuleRef < M > > {
71
+ this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory ( moduleFactory ) ;
72
72
73
- this . bootstrapApp ( ) ;
73
+ this . bootstrapApp ( ) ;
74
74
75
- return null ; // Make the compiler happy
76
- }
75
+ return null ; // Make the compiler happy
76
+ }
77
77
78
- bootstrapModule < M > (
79
- moduleType : Type < M > ,
80
- compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ]
81
- ) : Promise < NgModuleRef < M > > {
82
- this . _bootstrapper = ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ;
78
+ bootstrapModule < M > (
79
+ moduleType : Type < M > ,
80
+ compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ]
81
+ ) : Promise < NgModuleRef < M > > {
82
+ this . _bootstrapper = ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ;
83
83
84
- this . bootstrapApp ( ) ;
84
+ this . bootstrapApp ( ) ;
85
85
86
- return null ; // Make the compiler happy
87
- }
86
+ return null ; // Make the compiler happy
87
+ }
88
88
89
- private bootstrapApp ( ) {
90
- global . __onLiveSyncCore = ( ) => this . livesyncModule ( ) ;
89
+ private bootstrapApp ( ) {
90
+ global . __onLiveSyncCore = ( ) => this . livesyncModule ( ) ;
91
91
92
- const mainPageEntry = this . createNavigationEntry ( this . _bootstrapper ) ;
92
+ const mainPageEntry = this . createNavigationEntry ( this . _bootstrapper ) ;
93
93
94
- application . start ( mainPageEntry ) ;
95
- }
94
+ if ( this . appOptions && typeof this . appOptions . cssFile === "string" ) {
95
+ // TODO: All exported filed in ES6 modules should be read-only
96
+ // Change the case when tns-core-modules become ES6 compatible and there is a legal way to set cssFile
97
+ ( < any > application ) . cssFile = this . appOptions . cssFile ;
98
+ }
96
99
97
- livesyncModule ( ) : void {
98
- rendererLog ( "ANGULAR LiveSync Started" ) ;
100
+ application . start ( mainPageEntry ) ;
101
+ }
99
102
100
- onBeforeLivesync . next ( lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null ) ;
103
+ livesyncModule ( ) : void {
104
+ rendererLog ( "ANGULAR LiveSync Started" ) ;
101
105
102
- const mainPageEntry = this . createNavigationEntry (
103
- this . _bootstrapper ,
104
- compRef => onAfterLivesync . next ( compRef ) ,
105
- error => onAfterLivesync . error ( error ) ,
106
- true
107
- ) ;
108
- mainPageEntry . animated = false ;
109
- mainPageEntry . clearHistory = true ;
106
+ onBeforeLivesync . next ( lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null ) ;
110
107
111
- const frame = topmost ( ) ;
112
- if ( frame ) {
113
- if ( frame . currentPage && frame . currentPage . modal ) {
114
- frame . currentPage . modal . closeModal ( ) ;
115
- }
116
- frame . navigate ( mainPageEntry ) ;
117
- }
118
- }
119
-
120
- onDestroy ( callback : ( ) => void ) : void {
121
- this . platform . onDestroy ( callback ) ;
122
- }
123
-
124
- get injector ( ) : Injector {
125
- return this . platform . injector ;
126
- } ;
127
-
128
- destroy ( ) : void {
129
- this . platform . destroy ( ) ;
130
- }
131
-
132
- get destroyed ( ) : boolean {
133
- return this . platform . destroyed ;
134
- }
135
-
136
- private createNavigationEntry (
137
- bootstrapAction : BootstrapperAction ,
138
- resolve ?: ( comp : NgModuleRef < any > ) => void ,
139
- reject ?: ( e : Error ) => void ,
140
- isLivesync : boolean = false ,
141
- isReboot : boolean = false ) : NavigationEntry {
142
-
143
- const pageFactory : PageFactory = this . platform . injector . get ( PAGE_FACTORY ) ;
144
-
145
- const navEntry : NavigationEntry = {
146
- create : ( ) : Page => {
147
- let page = pageFactory ( { isBootstrap : true , isLivesync } ) ;
148
- if ( this . appOptions ) {
149
- page . actionBarHidden = this . appOptions . startPageActionBarHidden ;
108
+ const mainPageEntry = this . createNavigationEntry (
109
+ this . _bootstrapper ,
110
+ compRef => onAfterLivesync . next ( compRef ) ,
111
+ error => onAfterLivesync . error ( error ) ,
112
+ true
113
+ ) ;
114
+ mainPageEntry . animated = false ;
115
+ mainPageEntry . clearHistory = true ;
116
+
117
+ const frame = topmost ( ) ;
118
+ if ( frame ) {
119
+ if ( frame . currentPage && frame . currentPage . modal ) {
120
+ frame . currentPage . modal . closeModal ( ) ;
121
+ }
122
+ frame . navigate ( mainPageEntry ) ;
150
123
}
124
+ }
125
+
126
+ onDestroy ( callback : ( ) => void ) : void {
127
+ this . platform . onDestroy ( callback ) ;
128
+ }
129
+
130
+ get injector ( ) : Injector {
131
+ return this . platform . injector ;
132
+ } ;
151
133
152
- let onLoadedHandler = function ( ) {
153
- page . off ( "loaded" , onLoadedHandler ) ;
154
- // profiling.stop("application-start");
155
- rendererLog ( "Page loaded" ) ;
134
+ destroy ( ) : void {
135
+ this . platform . destroy ( ) ;
136
+ }
156
137
157
- // profiling.start("ng-bootstrap");
158
- rendererLog ( "BOOTSTRAPPING..." ) ;
159
- bootstrapAction ( ) . then ( ( moduleRef ) => {
160
- // profiling.stop("ng-bootstrap");
161
- rendererLog ( "ANGULAR BOOTSTRAP DONE." ) ;
162
- lastBootstrappedModule = new WeakRef ( moduleRef ) ;
138
+ get destroyed ( ) : boolean {
139
+ return this . platform . destroyed ;
140
+ }
163
141
164
- if ( resolve ) {
165
- resolve ( moduleRef ) ;
166
- }
167
- return moduleRef ;
168
- } , ( err ) => {
169
- rendererError ( "ERROR BOOTSTRAPPING ANGULAR" ) ;
170
- let errorMessage = err . message + "\n\n" + err . stack ;
171
- rendererError ( errorMessage ) ;
172
-
173
- let view = new TextView ( ) ;
174
- view . text = errorMessage ;
175
- page . content = view ;
176
-
177
- if ( reject ) {
178
- reject ( err ) ;
142
+ private createNavigationEntry (
143
+ bootstrapAction : BootstrapperAction ,
144
+ resolve ?: ( comp : NgModuleRef < any > ) => void ,
145
+ reject ?: ( e : Error ) => void ,
146
+ isLivesync : boolean = false ,
147
+ isReboot : boolean = false ) : NavigationEntry {
148
+
149
+ const pageFactory : PageFactory = this . platform . injector . get ( PAGE_FACTORY ) ;
150
+
151
+ const navEntry : NavigationEntry = {
152
+ create : ( ) : Page => {
153
+ let page = pageFactory ( { isBootstrap : true , isLivesync } ) ;
154
+ if ( this . appOptions ) {
155
+ page . actionBarHidden = this . appOptions . startPageActionBarHidden ;
156
+ }
157
+
158
+ let onLoadedHandler = function ( ) {
159
+ page . off ( "loaded" , onLoadedHandler ) ;
160
+ // profiling.stop("application-start");
161
+ rendererLog ( "Page loaded" ) ;
162
+
163
+ // profiling.start("ng-bootstrap");
164
+ rendererLog ( "BOOTSTRAPPING..." ) ;
165
+ bootstrapAction ( ) . then ( ( moduleRef ) => {
166
+ // profiling.stop("ng-bootstrap");
167
+ rendererLog ( "ANGULAR BOOTSTRAP DONE." ) ;
168
+ lastBootstrappedModule = new WeakRef ( moduleRef ) ;
169
+
170
+ if ( resolve ) {
171
+ resolve ( moduleRef ) ;
172
+ }
173
+ return moduleRef ;
174
+ } , ( err ) => {
175
+ rendererError ( "ERROR BOOTSTRAPPING ANGULAR" ) ;
176
+ let errorMessage = err . message + "\n\n" + err . stack ;
177
+ rendererError ( errorMessage ) ;
178
+
179
+ let view = new TextView ( ) ;
180
+ view . text = errorMessage ;
181
+ page . content = view ;
182
+
183
+ if ( reject ) {
184
+ reject ( err ) ;
185
+ }
186
+ } ) ;
187
+ } ;
188
+
189
+ page . on ( "loaded" , onLoadedHandler ) ;
190
+
191
+ return page ;
179
192
}
180
- } ) ;
181
193
} ;
182
194
183
- page . on ( "loaded" , onLoadedHandler ) ;
184
-
185
- return page ;
186
- }
187
- } ;
195
+ if ( isReboot ) {
196
+ navEntry . animated = false ;
197
+ navEntry . clearHistory = true ;
198
+ }
188
199
189
- if ( isReboot ) {
190
- navEntry . animated = false ;
191
- navEntry . clearHistory = true ;
200
+ return navEntry ;
192
201
}
193
202
194
- return navEntry ;
195
- }
196
-
197
- liveSyncApp ( ) {
198
- }
203
+ liveSyncApp ( ) {
204
+ }
199
205
}
0 commit comments