1
- import { ApplicationRef , EnvironmentProviders , NgModuleRef , NgZone , PlatformRef , Provider , Type , ɵinternalCreateApplication as internalCreateApplication } from '@angular/core' ;
1
+ import { ApplicationRef , EnvironmentProviders , NgModuleRef , NgZone , PlatformRef , Provider } from '@angular/core' ;
2
+ import {
3
+ Application ,
4
+ ApplicationEventData ,
5
+ Color ,
6
+ LaunchEventData ,
7
+ LayoutBase ,
8
+ profile ,
9
+ removeTaggedAdditionalCSS ,
10
+ TextView ,
11
+ Utils ,
12
+ View ,
13
+ } from '@nativescript/core' ;
14
+ import { Observable , Subject } from 'rxjs' ;
2
15
import { filter , map , take } from 'rxjs/operators' ;
3
- import { Application , ApplicationEventData , Color , LaunchEventData , LayoutBase , profile , removeTaggedAdditionalCSS , StackLayout , TextView , View , Utils , Trace } from '@nativescript/core' ;
4
16
import { AppHostView } from './app-host-view' ;
5
17
import { NativeScriptLoadingService } from './loading.service' ;
6
18
import { APP_ROOT_VIEW , DISABLE_ROOT_VIEW_HANDLING , NATIVESCRIPT_ROOT_MODULE_ID } from './tokens' ;
7
- import { Observable , Subject } from 'rxjs' ;
8
19
import { NativeScriptDebug } from './trace' ;
9
- import { NATIVESCRIPT_MODULE_PROVIDERS , NATIVESCRIPT_MODULE_STATIC_PROVIDERS } from './nativescript' ;
10
20
11
21
export interface AppLaunchView extends LayoutBase {
12
22
// called when the animation is to begin
@@ -45,7 +55,7 @@ export const postAngularBootstrap$ = new Subject<NgModuleEvent>();
45
55
*/
46
56
export const onBeforeLivesync : Observable < NgModuleRef < any > > = preAngularDisposal$ . pipe (
47
57
filter ( ( v ) => v . moduleType === 'main' && v . reason === 'hotreload' ) ,
48
- map ( ( v ) => v . reference as NgModuleRef < any > )
58
+ map ( ( v ) => v . reference as NgModuleRef < any > ) ,
49
59
) ;
50
60
/**
51
61
* @deprecated
@@ -55,7 +65,7 @@ export const onAfterLivesync: Observable<{
55
65
error ?: Error ;
56
66
} > = postAngularBootstrap$ . pipe (
57
67
filter ( ( v ) => v . moduleType === 'main' ) ,
58
- map ( ( v ) => ( { moduleRef : v . reference as NgModuleRef < any > } ) )
68
+ map ( ( v ) => ( { moduleRef : v . reference as NgModuleRef < any > } ) ) ,
59
69
) ;
60
70
export interface AppRunOptions < T , K > {
61
71
/**
@@ -92,7 +102,11 @@ if (import.meta['webpackHot']) {
92
102
} ;
93
103
}
94
104
95
- function emitModuleBootstrapEvent < T > ( ref : NgModuleRef < T > | ApplicationRef , name : 'main' | 'loading' , reason : NgModuleReason ) {
105
+ function emitModuleBootstrapEvent < T > (
106
+ ref : NgModuleRef < T > | ApplicationRef ,
107
+ name : 'main' | 'loading' ,
108
+ reason : NgModuleReason ,
109
+ ) {
96
110
postAngularBootstrap$ . next ( {
97
111
moduleType : name ,
98
112
reference : ref ,
@@ -136,7 +150,7 @@ function runZoneSyncTask(fn: () => void) {
136
150
} ,
137
151
( ) => {
138
152
//
139
- }
153
+ } ,
140
154
) ;
141
155
try {
142
156
// console.log(task.state);
@@ -198,22 +212,12 @@ function runSynchronously(fn: () => void, done?: () => void): void {
198
212
}
199
213
}
200
214
201
- function createProvidersConfig ( options ?: ApplicationConfig ) {
202
- return {
203
- appProviders : [ ...NATIVESCRIPT_MODULE_PROVIDERS , ...NATIVESCRIPT_MODULE_STATIC_PROVIDERS , ...( options ?. providers ?? [ ] ) ] ,
204
- // platformProviders: INTERNAL_BROWSER_PLATFORM_PROVIDERS
205
- } ;
206
- }
207
-
208
215
export interface ApplicationConfig {
209
216
/**
210
217
* List of providers that should be available to the root component and all its children.
211
218
*/
212
219
providers : Array < Provider | EnvironmentProviders > ;
213
220
}
214
- export function bootstrapApplication ( rootComponent : Type < unknown > , options ?: ApplicationConfig ) : Promise < ApplicationRef > {
215
- return internalCreateApplication ( { rootComponent, ...createProvidersConfig ( options ) } ) ;
216
- }
217
221
218
222
export function runNativeScriptAngularApp < T , K > ( options : AppRunOptions < T , K > ) {
219
223
let mainModuleRef : NgModuleRef < T > | ApplicationRef = null ;
@@ -301,7 +305,9 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
301
305
}
302
306
mainModuleRef = ref ;
303
307
304
- ( ref instanceof ApplicationRef ? ref . components [ 0 ] : ref ) . onDestroy ( ( ) => ( mainModuleRef = mainModuleRef === ref ? null : mainModuleRef ) ) ;
308
+ ( ref instanceof ApplicationRef ? ref . components [ 0 ] : ref ) . onDestroy (
309
+ ( ) => ( mainModuleRef = mainModuleRef === ref ? null : mainModuleRef ) ,
310
+ ) ;
305
311
updatePlatformRef ( ref , reason ) ;
306
312
const styleTag = ref . injector . get ( NATIVESCRIPT_ROOT_MODULE_ID ) ;
307
313
( ref instanceof ApplicationRef ? ref . components [ 0 ] : ref ) . onDestroy ( ( ) => {
@@ -317,7 +323,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
317
323
NativeScriptDebug . bootstrapLogError ( `Error bootstrapping app module:\n${ err . message } \n\n${ err . stack } ` ) ;
318
324
showErrorUI ( err ) ;
319
325
throw err ;
320
- }
326
+ } ,
321
327
) ,
322
328
( ) => {
323
329
if ( currentBootstrapId !== bootstrapId ) {
@@ -335,10 +341,16 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
335
341
return ;
336
342
}
337
343
loadingModuleRef = loadingRef ;
338
- ( loadingModuleRef instanceof ApplicationRef ? loadingModuleRef . components [ 0 ] : loadingModuleRef ) . onDestroy ( ( ) => ( loadingModuleRef = loadingModuleRef === loadingRef ? null : loadingModuleRef ) ) ;
344
+ ( loadingModuleRef instanceof ApplicationRef
345
+ ? loadingModuleRef . components [ 0 ]
346
+ : loadingModuleRef
347
+ ) . onDestroy ( ( ) => ( loadingModuleRef = loadingModuleRef === loadingRef ? null : loadingModuleRef ) ) ;
339
348
updatePlatformRef ( loadingRef , reason ) ;
340
349
const styleTag = loadingModuleRef . injector . get ( NATIVESCRIPT_ROOT_MODULE_ID ) ;
341
- ( loadingModuleRef instanceof ApplicationRef ? loadingModuleRef . components [ 0 ] : loadingModuleRef ) . onDestroy ( ( ) => {
350
+ ( loadingModuleRef instanceof ApplicationRef
351
+ ? loadingModuleRef . components [ 0 ]
352
+ : loadingModuleRef
353
+ ) . onDestroy ( ( ) => {
342
354
removeTaggedAdditionalCSS ( styleTag ) ;
343
355
} ) ;
344
356
setRootView ( loadingRef ) ;
@@ -352,7 +364,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
352
364
loadingService . readyToDestroy$
353
365
. pipe (
354
366
filter ( ( ready ) => ready ) ,
355
- take ( 1 )
367
+ take ( 1 ) ,
356
368
)
357
369
. subscribe ( ( ) => {
358
370
destroyRef ( loadingModuleRef , 'loading' , reason ) ;
@@ -364,11 +376,13 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
364
376
emitModuleBootstrapEvent ( loadingModuleRef , 'loading' , reason ) ;
365
377
} ,
366
378
( err ) => {
367
- NativeScriptDebug . bootstrapLogError ( `Error bootstrapping loading module:\n${ err . message } \n\n${ err . stack } ` ) ;
379
+ NativeScriptDebug . bootstrapLogError (
380
+ `Error bootstrapping loading module:\n${ err . message } \n\n${ err . stack } ` ,
381
+ ) ;
368
382
showErrorUI ( err ) ;
369
383
throw err ;
370
- }
371
- )
384
+ } ,
385
+ ) ,
372
386
) ;
373
387
} else if ( options . launchView ) {
374
388
let launchView = options . launchView ( reason ) ;
@@ -397,10 +411,12 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
397
411
} ) ;
398
412
} ;
399
413
} else {
400
- console . warn ( 'App is bootstrapping asynchronously (likely APP_INITIALIZER) but did not provide a launchView or LoadingModule.' ) ;
414
+ console . warn (
415
+ 'App is bootstrapping asynchronously (likely APP_INITIALIZER) but did not provide a launchView or LoadingModule.' ,
416
+ ) ;
401
417
}
402
418
}
403
- }
419
+ } ,
404
420
) ;
405
421
} catch ( err ) {
406
422
NativeScriptDebug . bootstrapLogError ( `Error in Bootstrap Function:\n${ err . message } \n\n${ err . stack } ` ) ;
@@ -431,7 +447,8 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
431
447
let oldAddEventListener ;
432
448
if ( typeof Zone !== 'undefined' && global . NativeScriptGlobals ?. events ?. [ Zone . __symbol__ ( 'addEventListener' ) ] ) {
433
449
oldAddEventListener = global . NativeScriptGlobals . events . addEventListener ;
434
- global . NativeScriptGlobals . events . addEventListener = global . NativeScriptGlobals . events [ Zone . __symbol__ ( 'addEventListener' ) ] ;
450
+ global . NativeScriptGlobals . events . addEventListener =
451
+ global . NativeScriptGlobals . events [ Zone . __symbol__ ( 'addEventListener' ) ] ;
435
452
}
436
453
if ( ! options . embedded ) {
437
454
Application . on ( Application . launchEvent , launchCallback ) ;
0 commit comments