File tree Expand file tree Collapse file tree
src/app/shared/theme-support Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,25 +11,14 @@ import { getDefaultThemeConfig } from '../../../config/config.util';
1111import { hasValue } from '../empty.util' ;
1212import { SetThemeAction } from './theme.actions' ;
1313import { BASE_THEME_NAME } from './theme.constants' ;
14+ import { NoOpAction } from '../ngrx/no-op.action' ;
1415
1516@Injectable ( )
1617export 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 ,
Original file line number Diff line number Diff 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 ( ) ) ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import {
2929import { GenericConstructor } from '../../core/shared/generic-constructor' ;
3030import {
3131 hasNoValue ,
32- hasValue ,
32+ hasValue , hasValueOperator ,
3333 isNotEmpty ,
3434} from '../empty.util' ;
3535import { 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 ) ,
You can’t perform that action at this time.
0 commit comments