1- import { Component , NgZone , ViewChild , AfterViewInit , OnDestroy , ChangeDetectorRef } from '@angular/core' ;
1+ import {
2+ ChangeDetectionStrategy ,
3+ ChangeDetectorRef ,
4+ Component ,
5+ NgZone ,
6+ OnDestroy ,
7+ ViewChild
8+ } from '@angular/core' ;
29import { ProjectProxy } from './model/project-proxy' ;
310import { Config , IdentifiedStaticSymbol , VisualizationConfig } from '../shared/data-format' ;
411import { formatError } from './shared/utils' ;
5- import { StateManager , Memento } from './model/state-manager' ;
12+ import { Memento , StateManager } from './model/state-manager' ;
613import { Theme } from '../shared/themes/color-map' ;
714import { IPCBus } from './model/ipc-bus' ;
815import { Message } from '../shared/ipc-constants' ;
@@ -17,9 +24,10 @@ import { KeyValue } from '@angular/common';
1724@Component ( {
1825 selector : 'ngrev-app' ,
1926 templateUrl : './app.component.html' ,
20- styleUrls : [ './app.component.scss' ]
27+ styleUrls : [ './app.component.scss' ] ,
28+ changeDetection : ChangeDetectionStrategy . OnPush
2129} )
22- export class AppComponent implements AfterViewInit , OnDestroy {
30+ export class AppComponent implements OnDestroy {
2331 projectSet = false ;
2432 loading = false ;
2533 queryList : KeyValue < string , IdentifiedStaticSymbol > [ ] = [ ] ;
@@ -35,9 +43,11 @@ export class AppComponent implements AfterViewInit, OnDestroy {
3543
3644 private _stopLoading = ( ) => {
3745 this . loading = false ;
46+ this . _cd . markForCheck ( ) ;
3847 } ;
3948 private _startLoading = ( ) => {
4049 this . loading = true ;
50+ this . _cd . markForCheck ( ) ;
4151 } ;
4252
4353 private _keyDownSubscription : Subscription ;
@@ -55,6 +65,30 @@ export class AppComponent implements AfterViewInit, OnDestroy {
5565 this . theme = config . themes [ config . theme ] ;
5666 this . showLibs = config . showLibs ;
5767 this . showModules = config . showModules ;
68+ this . _cd . markForCheck ( ) ;
69+ } ) ;
70+
71+ this . _ipcBus . on ( Message . ChangeTheme , ( _ : any , theme : string ) => {
72+ this . _ngZone . run ( ( ) => {
73+ this . theme = this . themes [ theme ] ;
74+ this . _cd . markForCheck ( ) ;
75+ } ) ;
76+ } ) ;
77+ this . _ipcBus . on ( Message . ToggleLibsMenuAction , ( ) => {
78+ this . _ngZone . run ( ( ) => {
79+ this . manager . toggleLibs ( ) . then ( ( ) => {
80+ this . manager . reloadAppState ( ) ;
81+ this . _cd . markForCheck ( ) ;
82+ } ) ;
83+ } ) ;
84+ } ) ;
85+ this . _ipcBus . on ( Message . ToggleModulesMenuAction , ( ) => {
86+ this . _ngZone . run ( ( ) => {
87+ this . manager . toggleModules ( ) . then ( ( ) => {
88+ this . manager . reloadAppState ( ) ;
89+ this . _cd . markForCheck ( ) ;
90+ } ) ;
91+ } ) ;
5892 } ) ;
5993
6094 this . maxWidth$ = fromEvent ( window , 'resize' ) . pipe (
@@ -73,25 +107,6 @@ export class AppComponent implements AfterViewInit, OnDestroy {
73107 ) . subscribe ( ) ;
74108 }
75109
76- ngAfterViewInit ( ) : void {
77- this . _ipcBus . on ( Message . ChangeTheme , ( _ : any , theme : string ) => {
78- this . theme = this . themes [ theme ] ;
79- this . _cd . detectChanges ( ) ;
80- } ) ;
81- this . _ipcBus . on ( Message . ToggleLibsMenuAction , ( ) => {
82- this . manager . toggleLibs ( ) . then ( ( ) => {
83- this . manager . reloadAppState ( ) ;
84- this . _cd . detectChanges ( ) ;
85- } ) ;
86- } ) ;
87- this . _ipcBus . on ( Message . ToggleModulesMenuAction , ( ) => {
88- this . manager . toggleModules ( ) . then ( ( ) => {
89- this . manager . reloadAppState ( ) ;
90- this . _cd . detectChanges ( ) ;
91- } ) ;
92- } ) ;
93- }
94-
95110 ngOnDestroy ( ) : void {
96111 this . _keyDownSubscription . unsubscribe ( ) ;
97112 }
@@ -137,15 +152,17 @@ the Angular's AoT compiler. Error during parsing:\n\n${formatError(error)}`
137152 }
138153
139154 restoreMemento ( memento : Memento ) : void {
140- this . manager
141- . restoreMemento ( memento )
142- . then ( this . _stopLoading )
143- . catch ( this . _stopLoading ) ;
155+ this . _ngZone . run ( ( ) => {
156+ this . manager
157+ . restoreMemento ( memento )
158+ . then ( this . _stopLoading )
159+ . catch ( this . _stopLoading ) ;
160+ } ) ;
144161 }
145162
146163 get initialized ( ) : VisualizationConfig < any > | null {
147164 return this . manager . getCurrentState ( ( ) => {
148- this . _cd . detectChanges ( ) ;
165+ this . _cd . markForCheck ( ) ;
149166 } ) ;
150167 }
151168
0 commit comments