@@ -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
import { rendererLog , rendererError } from "./trace" ;
@@ -35,160 +35,160 @@ let lastBootstrappedModule: WeakRef<NgModuleRef<any>>;
35
35
type BootstrapperAction = ( ) => Promise < NgModuleRef < any > > ;
36
36
37
37
interface BootstrapParams {
38
- appModuleType : Type < any > ;
39
- appOptions ?: AppOptions ;
38
+ appModuleType : Type < any > ;
39
+ appOptions ?: AppOptions ;
40
40
}
41
41
42
42
export interface AppOptions {
43
- bootInExistingPage : boolean ;
44
- cssFile ?: string ;
45
- startPageActionBarHidden ?: boolean ;
43
+ bootInExistingPage : boolean ;
44
+ cssFile ?: string ;
45
+ startPageActionBarHidden ?: boolean ;
46
46
}
47
47
48
48
export type PlatformFactory = ( extraProviders ?: Provider [ ] ) => PlatformRef ;
49
49
50
50
export class NativeScriptSanitizer extends Sanitizer {
51
- sanitize ( context : any , value : string ) : string {
52
- return value ;
53
- }
51
+ sanitize ( context : any , value : string ) : string {
52
+ return value ;
53
+ }
54
54
}
55
55
56
56
export const COMMON_PROVIDERS = [
57
- defaultPageFactoryProvider ,
58
- { provide : Sanitizer , useClass : NativeScriptSanitizer } ,
57
+ defaultPageFactoryProvider ,
58
+ { provide : Sanitizer , useClass : NativeScriptSanitizer }
59
59
] ;
60
60
61
61
export class NativeScriptPlatformRef extends PlatformRef {
62
- private _bootstrapper : BootstrapperAction ;
62
+ private _bootstrapper : BootstrapperAction ;
63
63
64
- constructor ( private platform : PlatformRef , private appOptions ?: AppOptions ) {
65
- super ( ) ;
66
- }
64
+ constructor ( private platform : PlatformRef , private appOptions ?: AppOptions ) {
65
+ super ( ) ;
66
+ }
67
67
68
- bootstrapModuleFactory < M > ( moduleFactory : NgModuleFactory < M > ) : Promise < NgModuleRef < M > > {
69
- this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory ( moduleFactory ) ;
68
+ bootstrapModuleFactory < M > ( moduleFactory : NgModuleFactory < M > ) : Promise < NgModuleRef < M > > {
69
+ this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory ( moduleFactory ) ;
70
70
71
- this . bootstrapApp ( ) ;
71
+ this . bootstrapApp ( ) ;
72
72
73
- return null ; //Make the compiler happy
74
- }
73
+ return null ; //Make the compiler happy
74
+ }
75
75
76
- bootstrapModule < M > ( moduleType : Type < M > , compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ] ) : Promise < NgModuleRef < M > > {
77
- this . _bootstrapper = ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ;
76
+ bootstrapModule < M > ( moduleType : Type < M > , compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ] ) : Promise < NgModuleRef < M > > {
77
+ this . _bootstrapper = ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ;
78
78
79
- this . bootstrapApp ( ) ;
79
+ this . bootstrapApp ( ) ;
80
+
81
+ return null ; //Make the compiler happy
82
+ }
80
83
81
- return null ; //Make the compiler happy
82
- }
84
+ private bootstrapApp ( ) {
85
+ global . __onLiveSyncCore = ( ) => this . livesyncModule ( ) ;
83
86
84
- private bootstrapApp ( ) {
85
- global . __onLiveSyncCore = ( ) => this . livesyncModule ( ) ;
87
+ const mainPageEntry = this . createNavigationEntry ( this . _bootstrapper ) ;
86
88
87
- const mainPageEntry = this . createNavigationEntry ( this . _bootstrapper ) ;
89
+ application . start ( mainPageEntry ) ;
90
+ }
88
91
89
- application . start ( mainPageEntry ) ;
90
- }
92
+ livesyncModule ( ) : void {
93
+ rendererLog ( "ANGULAR LiveSync Started" ) ;
91
94
92
- livesyncModule ( ) : void {
93
- rendererLog ( "ANGULAR LiveSync Started" ) ;
95
+ onBeforeLivesync . next ( lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null ) ;
94
96
95
- onBeforeLivesync . next ( lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null ) ;
97
+ const mainPageEntry = this . createNavigationEntry (
98
+ this . _bootstrapper ,
99
+ compRef => onAfterLivesync . next ( compRef ) ,
100
+ error => onAfterLivesync . error ( error ) ,
101
+ true
102
+ ) ;
103
+ mainPageEntry . animated = false ;
104
+ mainPageEntry . clearHistory = true ;
96
105
97
- const mainPageEntry = this . createNavigationEntry (
98
- this . _bootstrapper ,
99
- compRef => onAfterLivesync . next ( compRef ) ,
100
- error => onAfterLivesync . error ( error ) ,
101
- true
102
- ) ;
103
- mainPageEntry . animated = false ;
104
- mainPageEntry . clearHistory = true ;
106
+ const frame = topmost ( ) ;
107
+ if ( frame ) {
108
+ if ( frame . currentPage && frame . currentPage . modal ) {
109
+ frame . currentPage . modal . closeModal ( ) ;
110
+ }
111
+ frame . navigate ( mainPageEntry ) ;
112
+ }
113
+ }
105
114
106
- const frame = topmost ( ) ;
107
- if ( frame ) {
108
- if ( frame . currentPage && frame . currentPage . modal ) {
109
- frame . currentPage . modal . closeModal ( ) ;
110
- }
111
- frame . navigate ( mainPageEntry ) ;
115
+ onDestroy ( callback : ( ) => void ) : void {
116
+ this . platform . onDestroy ( callback ) ;
112
117
}
113
- }
114
-
115
- onDestroy ( callback : ( ) => void ) : void {
116
- this . platform . onDestroy ( callback ) ;
117
- }
118
-
119
- get injector ( ) : Injector {
120
- return this . platform . injector ;
121
- } ;
122
-
123
- destroy ( ) : void {
124
- this . platform . destroy ( ) ;
125
- }
126
-
127
- get destroyed ( ) : boolean {
128
- return this . platform . destroyed ;
129
- }
130
-
131
- private createNavigationEntry (
132
- bootstrapAction : BootstrapperAction ,
133
- resolve ?: ( comp : NgModuleRef < any > ) => void ,
134
- reject ?: ( e : Error ) => void ,
135
- isLivesync : boolean = false ,
136
- isReboot : boolean = false ) : NavigationEntry {
137
-
138
- const pageFactory : PageFactory = this . platform . injector . get ( PAGE_FACTORY ) ;
139
-
140
- const navEntry : NavigationEntry = {
141
- create : ( ) : Page => {
142
- let page = pageFactory ( { isBootstrap : true , isLivesync } ) ;
143
- if ( this . appOptions ) {
144
- page . actionBarHidden = this . appOptions . startPageActionBarHidden ;
145
- }
146
118
147
- let onLoadedHandler = function ( args ) {
148
- page . off ( 'loaded' , onLoadedHandler ) ;
149
- //profiling.stop('application-start');
150
- rendererLog ( 'Page loaded' ) ;
119
+ get injector ( ) : Injector {
120
+ return this . platform . injector ;
121
+ } ;
151
122
152
- //profiling.start('ng-bootstrap');
153
- rendererLog ( 'BOOTSTRAPPING...' ) ;
154
- bootstrapAction ( ) . then ( ( moduleRef ) => {
155
- //profiling.stop('ng-bootstrap');
156
- rendererLog ( 'ANGULAR BOOTSTRAP DONE.' ) ;
157
- lastBootstrappedModule = new WeakRef ( moduleRef ) ;
123
+ destroy ( ) : void {
124
+ this . platform . destroy ( ) ;
125
+ }
158
126
159
- if ( resolve ) {
160
- resolve ( moduleRef ) ;
161
- }
162
- return moduleRef ;
163
- } , ( err ) => {
164
- rendererError ( 'ERROR BOOTSTRAPPING ANGULAR' ) ;
165
- let errorMessage = err . message + "\n\n" + err . stack ;
166
- rendererError ( errorMessage ) ;
167
-
168
- let view = new TextView ( ) ;
169
- view . text = errorMessage ;
170
- page . content = view ;
171
-
172
- if ( reject ) {
173
- reject ( err ) ;
127
+ get destroyed ( ) : boolean {
128
+ return this . platform . destroyed ;
129
+ }
130
+
131
+ private createNavigationEntry (
132
+ bootstrapAction : BootstrapperAction ,
133
+ resolve ?: ( comp : NgModuleRef < any > ) => void ,
134
+ reject ?: ( e : Error ) => void ,
135
+ isLivesync : boolean = false ,
136
+ isReboot : boolean = false ) : NavigationEntry {
137
+
138
+ const pageFactory : PageFactory = this . platform . injector . get ( PAGE_FACTORY ) ;
139
+
140
+ const navEntry : NavigationEntry = {
141
+ create : ( ) : Page => {
142
+ let page = pageFactory ( { isBootstrap : true , isLivesync } ) ;
143
+ if ( this . appOptions ) {
144
+ page . actionBarHidden = this . appOptions . startPageActionBarHidden ;
145
+ }
146
+
147
+ let onLoadedHandler = function ( args ) {
148
+ page . off ( 'loaded' , onLoadedHandler ) ;
149
+ //profiling.stop('application-start');
150
+ rendererLog ( 'Page loaded' ) ;
151
+
152
+ //profiling.start('ng-bootstrap');
153
+ rendererLog ( 'BOOTSTRAPPING...' ) ;
154
+ bootstrapAction ( ) . then ( ( moduleRef ) => {
155
+ //profiling.stop('ng-bootstrap');
156
+ rendererLog ( 'ANGULAR BOOTSTRAP DONE.' ) ;
157
+ lastBootstrappedModule = new WeakRef ( moduleRef ) ;
158
+
159
+ if ( resolve ) {
160
+ resolve ( moduleRef ) ;
161
+ }
162
+ return moduleRef ;
163
+ } , ( err ) => {
164
+ rendererError ( 'ERROR BOOTSTRAPPING ANGULAR' ) ;
165
+ let errorMessage = err . message + "\n\n" + err . stack ;
166
+ rendererError ( errorMessage ) ;
167
+
168
+ let view = new TextView ( ) ;
169
+ view . text = errorMessage ;
170
+ page . content = view ;
171
+
172
+ if ( reject ) {
173
+ reject ( err ) ;
174
+ }
175
+ } ) ;
176
+ } ;
177
+
178
+ page . on ( 'loaded' , onLoadedHandler ) ;
179
+
180
+ return page ;
174
181
}
175
- } ) ;
176
182
} ;
177
183
178
- page . on ( 'loaded' , onLoadedHandler ) ;
179
-
180
- return page ;
181
- }
182
- } ;
184
+ if ( isReboot ) {
185
+ navEntry . animated = false ;
186
+ navEntry . clearHistory = true ;
187
+ }
183
188
184
- if ( isReboot ) {
185
- navEntry . animated = false ;
186
- navEntry . clearHistory = true ;
189
+ return navEntry ;
187
190
}
188
191
189
- return navEntry ;
190
- }
191
-
192
- liveSyncApp ( ) {
193
- }
192
+ liveSyncApp ( ) {
193
+ }
194
194
}
0 commit comments