arch(sprint1): centralize startup in platform runtime
This commit is contained in:
26
src/app/core/runtime/platform-runtime-state.service.ts
Normal file
26
src/app/core/runtime/platform-runtime-state.service.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { FeatureFlagsConfig, LocalizationConfig, PermissionsConfig } from '../../shared/models/config';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PlatformRuntimeStateService {
|
||||
private readonly initializedState = signal(false);
|
||||
private readonly localizationState = signal<LocalizationConfig | null>(null);
|
||||
private readonly featureFlagsState = signal<FeatureFlagsConfig | null>(null);
|
||||
private readonly permissionsState = signal<PermissionsConfig | null>(null);
|
||||
|
||||
readonly initialized = this.initializedState.asReadonly();
|
||||
readonly localization = this.localizationState.asReadonly();
|
||||
readonly featureFlags = this.featureFlagsState.asReadonly();
|
||||
readonly permissions = this.permissionsState.asReadonly();
|
||||
|
||||
markInitialized(next: {
|
||||
localization: LocalizationConfig;
|
||||
featureFlags: FeatureFlagsConfig;
|
||||
permissions: PermissionsConfig;
|
||||
}): void {
|
||||
this.localizationState.set(next.localization);
|
||||
this.featureFlagsState.set(next.featureFlags);
|
||||
this.permissionsState.set(next.permissions);
|
||||
this.initializedState.set(true);
|
||||
}
|
||||
}
|
||||
45
src/app/core/runtime/platform-runtime.service.ts
Normal file
45
src/app/core/runtime/platform-runtime.service.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { ConfigService } from '../config/config.service';
|
||||
import { BrandingEngineService } from '../../theme/runtime/branding-engine.service';
|
||||
import { ThemeEngineService } from '../../theme/runtime/theme-engine.service';
|
||||
import { WidgetRegistryBootstrapService } from '../../widgets/registry/widget-registry.bootstrap.service';
|
||||
import { PlatformRuntimeStateService } from './platform-runtime-state.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PlatformRuntimeService {
|
||||
private initializing = false;
|
||||
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
private readonly widgetRegistryBootstrap: WidgetRegistryBootstrapService,
|
||||
private readonly themeEngine: ThemeEngineService,
|
||||
private readonly brandingEngine: BrandingEngineService,
|
||||
private readonly runtimeState: PlatformRuntimeStateService
|
||||
) {}
|
||||
|
||||
initialize(): void {
|
||||
if (this.initializing || this.runtimeState.initialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initializing = true;
|
||||
|
||||
this.configService.loadBootstrap().pipe(take(1)).subscribe({
|
||||
next: (bootstrap) => {
|
||||
this.widgetRegistryBootstrap.registerDefaults();
|
||||
this.themeEngine.applyTheme(bootstrap.theme);
|
||||
this.brandingEngine.applyBranding(bootstrap.branding);
|
||||
this.runtimeState.markInitialized({
|
||||
localization: bootstrap.localization,
|
||||
featureFlags: bootstrap.featureFlags,
|
||||
permissions: bootstrap.permissions
|
||||
});
|
||||
this.initializing = false;
|
||||
},
|
||||
error: () => {
|
||||
this.initializing = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user