1
- import { Injectable , NgZone , ApplicationRef , Injector } from '@angular/core' ;
1
+ import { Injectable , NgZone , ApplicationRef , Injector , computed , signal } from '@angular/core' ;
2
2
import { of , Observable , Subject , forkJoin , from , throwError } from 'rxjs' ;
3
3
import { AssetsLoader } from '../assets-loader' ;
4
4
import { PlanetApplication , PlanetRouterEvent , SwitchModes , PlanetOptions } from '../planet.class' ;
@@ -54,6 +54,8 @@ export class PlanetApplicationLoader {
54
54
55
55
private appsLoadingStart$ = new Subject < AppsLoadingStartEvent > ( ) ;
56
56
57
+ private innerLoading = signal ( false ) ;
58
+
57
59
public get appStatusChange ( ) : Observable < AppStatusChangeEvent > {
58
60
return this . appStatusChange$ . asObservable ( ) ;
59
61
}
@@ -62,8 +64,13 @@ export class PlanetApplicationLoader {
62
64
return this . appsLoadingStart$ . asObservable ( ) ;
63
65
}
64
66
67
+ /**
68
+ * @deprecated please use loading signal
69
+ */
65
70
public loadingDone = false ;
66
71
72
+ public loading = this . innerLoading . asReadonly ( ) ;
73
+
67
74
constructor (
68
75
private assetsLoader : AssetsLoader ,
69
76
private planetApplicationService : PlanetApplicationService ,
@@ -73,9 +80,7 @@ export class PlanetApplicationLoader {
73
80
applicationRef : ApplicationRef
74
81
) {
75
82
if ( getApplicationLoader ( ) ) {
76
- throw new Error (
77
- 'PlanetApplicationLoader has been injected in the portal, repeated injection is not allowed'
78
- ) ;
83
+ throw new Error ( 'PlanetApplicationLoader has been injected in the portal, repeated injection is not allowed' ) ;
79
84
}
80
85
81
86
this . options = {
@@ -97,9 +102,7 @@ export class PlanetApplicationLoader {
97
102
this . ngZone . run ( ( ) => {
98
103
const fromStatus = this . appsStatus . get ( app ) ;
99
104
debug (
100
- `app(${ app . name } ) status change: ${ fromStatus ? ApplicationStatus [ fromStatus ] : 'empty' } => ${
101
- ApplicationStatus [ status ]
102
- } `
105
+ `app(${ app . name } ) status change: ${ fromStatus ? ApplicationStatus [ fromStatus ] : 'empty' } => ${ ApplicationStatus [ status ] } `
103
106
) ;
104
107
this . appsStatus . set ( app , status ) ;
105
108
this . appStatusChange$ . next ( {
@@ -109,10 +112,7 @@ export class PlanetApplicationLoader {
109
112
} ) ;
110
113
}
111
114
112
- private getAppStatusChange$ (
113
- app : PlanetApplication ,
114
- status = ApplicationStatus . bootstrapped
115
- ) : Observable < PlanetApplication > {
115
+ private getAppStatusChange$ ( app : PlanetApplication , status = ApplicationStatus . bootstrapped ) : Observable < PlanetApplication > {
116
116
return this . appStatusChange . pipe (
117
117
filter ( event => {
118
118
return event . app === app && event . status === status ;
@@ -140,6 +140,7 @@ export class PlanetApplicationLoader {
140
140
private setLoadingDone ( ) {
141
141
this . ngZone . run ( ( ) => {
142
142
this . loadingDone = true ;
143
+ this . innerLoading . set ( false ) ;
143
144
} ) ;
144
145
}
145
146
@@ -188,9 +189,7 @@ export class PlanetApplicationLoader {
188
189
appStatus === ApplicationStatus . loadError
189
190
) {
190
191
debug (
191
- `app(${ app . name } ) status is ${
192
- ApplicationStatus [ appStatus as ApplicationStatus ]
193
- } , start load assets`
192
+ `app(${ app . name } ) status is ${ ApplicationStatus [ appStatus as ApplicationStatus ] } , start load assets`
194
193
) ;
195
194
hasAppsNeedLoadingAssets = true ;
196
195
return this . ngZone . runOutsideAngular ( ( ) => {
@@ -202,6 +201,7 @@ export class PlanetApplicationLoader {
202
201
} ) ;
203
202
if ( hasAppsNeedLoadingAssets ) {
204
203
this . loadingDone = false ;
204
+ this . innerLoading . set ( true ) ;
205
205
}
206
206
return loadApps$ . length > 0 ? forkJoin ( loadApps$ ) : of ( [ ] as PlanetApplication [ ] ) ;
207
207
} ) ,
@@ -212,19 +212,15 @@ export class PlanetApplicationLoader {
212
212
switchMap ( app => {
213
213
const appStatus = this . appsStatus . get ( app ) ;
214
214
if ( appStatus === ApplicationStatus . bootstrapped ) {
215
- debug (
216
- `[routeChange] app(${ app . name } ) status is bootstrapped, show app and active`
217
- ) ;
215
+ debug ( `[routeChange] app(${ app . name } ) status is bootstrapped, show app and active` ) ;
218
216
this . showApp ( app ) ;
219
217
const appRef = getPlanetApplicationRef ( app . name ) ;
220
218
appRef ?. navigateByUrl ( event . url ) ;
221
219
this . setAppStatus ( app , ApplicationStatus . active ) ;
222
220
this . setLoadingDone ( ) ;
223
221
return of ( app ) ;
224
222
} else if ( appStatus === ApplicationStatus . assetsLoaded ) {
225
- debug (
226
- `[routeChange] app(${ app . name } ) status is assetsLoaded, start bootstrapping`
227
- ) ;
223
+ debug ( `[routeChange] app(${ app . name } ) status is assetsLoaded, start bootstrapping` ) ;
228
224
return this . bootstrapApp ( app ) . pipe (
229
225
map ( ( ) => {
230
226
debug ( `app(${ app . name } ) bootstrapped success, active it` ) ;
@@ -237,9 +233,7 @@ export class PlanetApplicationLoader {
237
233
debug ( `[routeChange] app(${ app . name } ) is active, do nothings` ) ;
238
234
const appRef = getPlanetApplicationRef ( app . name ) ;
239
235
// Backwards compatibility sub app use old version which has not getCurrentRouterStateUrl
240
- const currentUrl = appRef ?. getCurrentRouterStateUrl
241
- ? appRef . getCurrentRouterStateUrl ( )
242
- : '' ;
236
+ const currentUrl = appRef ?. getCurrentRouterStateUrl ? appRef . getCurrentRouterStateUrl ( ) : '' ;
243
237
if ( currentUrl !== event . url ) {
244
238
appRef ?. navigateByUrl ( event . url ) ;
245
239
}
@@ -253,9 +247,7 @@ export class PlanetApplicationLoader {
253
247
return this . getAppStatusChange$ ( app ) . pipe (
254
248
take ( 1 ) ,
255
249
map ( ( ) => {
256
- debug (
257
- `app(${ app . name } ) status is bootstrapped by subscribe status change, active it`
258
- ) ;
250
+ debug ( `app(${ app . name } ) status is bootstrapped by subscribe status change, active it` ) ;
259
251
this . setAppStatus ( app , ApplicationStatus . active ) ;
260
252
this . showApp ( app ) ;
261
253
return app ;
@@ -355,10 +347,7 @@ export class PlanetApplicationLoader {
355
347
}
356
348
}
357
349
358
- private bootstrapApp (
359
- app : PlanetApplication ,
360
- defaultStatus : 'hidden' | 'display' = 'display'
361
- ) : Observable < PlanetApplicationRef > {
350
+ private bootstrapApp ( app : PlanetApplication , defaultStatus : 'hidden' | 'display' = 'display' ) : Observable < PlanetApplicationRef > {
362
351
debug ( `app(${ app . name } ) start bootstrapping` ) ;
363
352
this . setAppStatus ( app , ApplicationStatus . bootstrapping ) ;
364
353
const appRef = getPlanetApplicationRef ( app . name ) ;
@@ -517,11 +506,7 @@ export class PlanetApplicationLoader {
517
506
return getPlanetApplicationRef ( app . name ) ;
518
507
} )
519
508
) ;
520
- } else if (
521
- [ ApplicationStatus . assetsLoading , ApplicationStatus . assetsLoaded , ApplicationStatus . bootstrapping ] . includes (
522
- status
523
- )
524
- ) {
509
+ } else if ( [ ApplicationStatus . assetsLoading , ApplicationStatus . assetsLoaded , ApplicationStatus . bootstrapping ] . includes ( status ) ) {
525
510
debug ( `preload app(${ app . name } ), status is ${ ApplicationStatus [ status ] } , return until bootstrapped` ) ;
526
511
return this . getAppStatusChange$ ( app ) . pipe (
527
512
take ( 1 ) ,
0 commit comments