phase-9: add builder sandbox for in-memory configuration editing
This commit is contained in:
52
src/app/facades/builder/builder-config.facade.ts
Normal file
52
src/app/facades/builder/builder-config.facade.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Injectable, computed, signal } from '@angular/core';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { BootstrapConfig } from '../../shared/models/config';
|
||||
import { ConfigService } from '../../core/config/config.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class BuilderConfigFacade {
|
||||
private readonly bootstrapState = signal<BootstrapConfig | null>(null);
|
||||
|
||||
readonly bootstrap = this.bootstrapState.asReadonly();
|
||||
readonly branding = computed(() => this.bootstrapState()?.branding ?? null);
|
||||
readonly featureFlags = computed(() => this.bootstrapState()?.featureFlags ?? null);
|
||||
|
||||
constructor(private readonly configService: ConfigService) {}
|
||||
|
||||
load(): void {
|
||||
this.configService.loadBootstrap().pipe(take(1)).subscribe({
|
||||
next: (config) => this.bootstrapState.set(JSON.parse(JSON.stringify(config)) as BootstrapConfig),
|
||||
error: () => this.bootstrapState.set(null)
|
||||
});
|
||||
}
|
||||
|
||||
updateBrandName(nextBrandName: string): void {
|
||||
const current = this.bootstrapState();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bootstrapState.set({
|
||||
...current,
|
||||
branding: {
|
||||
...current.branding,
|
||||
brandName: nextBrandName
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setFeatureFlag(flag: string, enabled: boolean): void {
|
||||
const current = this.bootstrapState();
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bootstrapState.set({
|
||||
...current,
|
||||
featureFlags: {
|
||||
...current.featureFlags,
|
||||
[flag]: enabled
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user