@wolkabout/commons 0.0.39 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -66,7 +66,7 @@ import * as i32 from '@angular/cdk/drag-drop';
|
|
|
66
66
|
import { DragDropModule } from '@angular/cdk/drag-drop';
|
|
67
67
|
import * as i0 from '@angular/core';
|
|
68
68
|
import { NgModule, InjectionToken, inject, Injectable, Injector, runInInjectionContext, DOCUMENT, Inject, Input, Directive, forwardRef, HostListener, TemplateRef, PLATFORM_ID, Pipe, ViewChild, ContentChild, Optional, Self, Component, input, computed, untracked, signal, viewChild, afterNextRender, effect, output, afterRenderEffect, contentChild } from '@angular/core';
|
|
69
|
-
import { BehaviorSubject, catchError, of, switchMap, EMPTY, tap, filter, map, combineLatestWith, from, distinctUntilChanged, shareReplay, merge, Subject, takeUntil, combineLatest, take, first } from 'rxjs';
|
|
69
|
+
import { BehaviorSubject, catchError, of, switchMap, EMPTY, tap, filter, map, combineLatestWith, forkJoin, from, distinctUntilChanged, shareReplay, merge, Subject, takeUntil, combineLatest, take, first } from 'rxjs';
|
|
70
70
|
import { jwtDecode } from 'jwt-decode';
|
|
71
71
|
import { loadRemoteModule } from '@angular-architects/native-federation';
|
|
72
72
|
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
|
@@ -513,46 +513,39 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImpor
|
|
|
513
513
|
|
|
514
514
|
class FeatureRegistry {
|
|
515
515
|
injector = inject(Injector);
|
|
516
|
-
|
|
516
|
+
loadedFeatures = [];
|
|
517
517
|
_features$ = new BehaviorSubject([]);
|
|
518
|
-
expectedFeatures = null;
|
|
519
518
|
/**
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
* If this isn't set, the registration of the feature will output values every time.
|
|
519
|
+
* Call when deploying a standalone app or when there are no external modules to load.
|
|
520
|
+
* Immediately emits the currently registered features.
|
|
523
521
|
*/
|
|
524
|
-
|
|
525
|
-
this.
|
|
522
|
+
noExternalModules() {
|
|
523
|
+
this._features$.next([...this.loadedFeatures]);
|
|
526
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* Call when deploying a host application.
|
|
527
|
+
* Emits the registered features once all external modules loaded (successfully or unsuccessfully).
|
|
528
|
+
*/
|
|
527
529
|
loadExternalFeatures(features) {
|
|
528
|
-
features.
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
530
|
+
if (!features || features.length === 0) {
|
|
531
|
+
this.noExternalModules();
|
|
532
|
+
}
|
|
533
|
+
forkJoin(features.map((feature) => from(loadRemoteModule(feature.remote, feature.feature)).pipe(map(module => module.default), catchError((error) => {
|
|
534
|
+
console.warn("Unable to load: ", feature.remote + '/' + feature.feature, error);
|
|
535
|
+
return of(null);
|
|
536
|
+
})))).subscribe((results) => {
|
|
537
|
+
results.forEach((feature) => {
|
|
533
538
|
if (feature) {
|
|
534
539
|
this.registerFeature(feature);
|
|
535
540
|
}
|
|
536
|
-
else {
|
|
537
|
-
this.features.push(null);
|
|
538
|
-
}
|
|
539
541
|
});
|
|
542
|
+
this._features$.next([...this.loadedFeatures]);
|
|
540
543
|
});
|
|
541
544
|
}
|
|
542
545
|
registerFeature(feature) {
|
|
543
|
-
this.
|
|
546
|
+
this.loadedFeatures.push(feature);
|
|
544
547
|
runInInjectionContext(this.injector, () => feature.init?.());
|
|
545
548
|
console.info('Loaded feature: ', feature.name);
|
|
546
|
-
this.finalizeLoading();
|
|
547
|
-
}
|
|
548
|
-
finalizeLoading() {
|
|
549
|
-
const loadedFeatures = this.features.filter((feature) => !!feature);
|
|
550
|
-
if (!this.expectedFeatures) {
|
|
551
|
-
this._features$.next(loadedFeatures);
|
|
552
|
-
}
|
|
553
|
-
else if (this.features.length === this.expectedFeatures) {
|
|
554
|
-
this._features$.next(loadedFeatures);
|
|
555
|
-
}
|
|
556
549
|
}
|
|
557
550
|
get features$() {
|
|
558
551
|
return this._features$.asObservable();
|