Skip to content

Commit 3d5d24e

Browse files
committed
129694: PoC #4123 solution
1 parent b076738 commit 3d5d24e

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

src/app/shared/theme-support/theme.effects.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,14 @@ import { getDefaultThemeConfig } from '../../../config/config.util';
1111
import { hasValue } from '../empty.util';
1212
import { SetThemeAction } from './theme.actions';
1313
import { BASE_THEME_NAME } from './theme.constants';
14+
import { NoOpAction } from '../ngrx/no-op.action';
1415

1516
@Injectable()
1617
export class ThemeEffects {
1718
/**
1819
* Initialize with a theme that doesn't depend on the route.
1920
*/
20-
initTheme$ = createEffect(() =>
21-
this.actions$.pipe(
22-
ofType(ROOT_EFFECTS_INIT),
23-
map(() => {
24-
const defaultThemeConfig = getDefaultThemeConfig();
25-
if (hasValue(defaultThemeConfig)) {
26-
return new SetThemeAction(defaultThemeConfig.name);
27-
} else {
28-
return new SetThemeAction(BASE_THEME_NAME);
29-
}
30-
}),
31-
),
32-
);
21+
3322

3423
constructor(
3524
private actions$: Actions,

src/app/shared/theme-support/theme.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ export class ThemeService {
383383
take(1),
384384
map((theme: Theme) => this.getActionForMatch(theme, currentTheme)),
385385
);
386+
} else if (hasNoValue(currentTheme)) {
387+
const defaultThemeConfig = getDefaultThemeConfig();
388+
if (hasValue(defaultThemeConfig)) {
389+
return [new SetThemeAction(defaultThemeConfig.name)];
390+
} else {
391+
return [new SetThemeAction(BASE_THEME_NAME)];
392+
}
386393
} else {
387394
// If there are no themes configured, do nothing
388395
return observableOf(new NoOpAction());

src/app/shared/theme-support/themed.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
import { GenericConstructor } from '../../core/shared/generic-constructor';
3030
import {
3131
hasNoValue,
32-
hasValue,
32+
hasValue, hasValueOperator,
3333
isNotEmpty,
3434
} from '../empty.util';
3535
import { BASE_THEME_NAME } from './theme.constants';
@@ -71,6 +71,7 @@ export abstract class ThemedComponent<T extends object> implements AfterViewInit
7171
protected abstract getComponentName(): string;
7272

7373
protected abstract importThemedComponent(themeName: string): Promise<any>;
74+
7475
protected abstract importUnthemedComponent(): Promise<any>;
7576

7677
ngOnChanges(changes: SimpleChanges): void {
@@ -99,16 +100,17 @@ export abstract class ThemedComponent<T extends object> implements AfterViewInit
99100
}
100101

101102
initComponentInstance(changes?: SimpleChanges) {
102-
this.themeSub = this.themeService?.getThemeName$().subscribe(() => {
103-
this.renderComponentInstance(changes);
104-
});
103+
this.themeSub = this.themeService?.getThemeName$()
104+
.pipe(hasValueOperator())
105+
.subscribe(() => {
106+
this.renderComponentInstance(changes);
107+
});
105108
}
106109

107110
protected renderComponentInstance(changes?: SimpleChanges): void {
108111
if (hasValue(this.lazyLoadSub)) {
109112
this.lazyLoadSub.unsubscribe();
110113
}
111-
112114
if (hasNoValue(this.lazyLoadObs)) {
113115
this.lazyLoadObs = combineLatest([
114116
observableOf(changes),

0 commit comments

Comments
 (0)