Dashboard performance improvements by changing change detection strategy to OnPush
This commit is contained in:
parent
634df64692
commit
c768fcbac1
@ -15,6 +15,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
Injector,
|
Injector,
|
||||||
Input,
|
Input,
|
||||||
@ -73,6 +74,7 @@ export class AliasesEntitySelectComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
constructor(private translate: TranslateService,
|
constructor(private translate: TranslateService,
|
||||||
private overlay: Overlay,
|
private overlay: Overlay,
|
||||||
|
private cd: ChangeDetectorRef,
|
||||||
private breakpointObserver: BreakpointObserver,
|
private breakpointObserver: BreakpointObserver,
|
||||||
private viewContainerRef: ViewContainerRef) {
|
private viewContainerRef: ViewContainerRef) {
|
||||||
}
|
}
|
||||||
@ -179,6 +181,7 @@ export class AliasesEntitySelectComponent implements OnInit, OnDestroy {
|
|||||||
displayValue = this.translate.instant('entity.entities');
|
displayValue = this.translate.instant('entity.entities');
|
||||||
}
|
}
|
||||||
this.displayValue = displayValue;
|
this.displayValue = displayValue;
|
||||||
|
this.cd.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateEntityAliasesInfo() {
|
private updateEntityAliasesInfo() {
|
||||||
|
|||||||
@ -226,8 +226,6 @@
|
|||||||
<mat-drawer class="tb-details-drawer"
|
<mat-drawer class="tb-details-drawer"
|
||||||
[opened]="isEditingWidget || isAddingWidget"
|
[opened]="isEditingWidget || isAddingWidget"
|
||||||
(openedStart)="detailsDrawerOpenedStart()"
|
(openedStart)="detailsDrawerOpenedStart()"
|
||||||
(opened)="detailsDrawerOpened()"
|
|
||||||
(closedStart)="detailsDrawerClosedStart()"
|
|
||||||
(closed)="detailsDrawerClosed()"
|
(closed)="detailsDrawerClosed()"
|
||||||
mode="over"
|
mode="over"
|
||||||
position="end">
|
position="end">
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ChangeDetectionStrategy,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
Component, ElementRef,
|
Component, ElementRef,
|
||||||
Inject,
|
Inject,
|
||||||
@ -134,7 +135,7 @@ import {
|
|||||||
templateUrl: './dashboard-page.component.html',
|
templateUrl: './dashboard-page.component.html',
|
||||||
styleUrls: ['./dashboard-page.component.scss'],
|
styleUrls: ['./dashboard-page.component.scss'],
|
||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
// changeDetection: ChangeDetectionStrategy.OnPush
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class DashboardPageComponent extends PageComponent implements IDashboardController, OnInit, OnDestroy {
|
export class DashboardPageComponent extends PageComponent implements IDashboardController, OnInit, OnDestroy {
|
||||||
|
|
||||||
@ -425,9 +426,9 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
}
|
}
|
||||||
|
|
||||||
public runChangeDetection() {
|
public runChangeDetection() {
|
||||||
/*setTimeout(() => {
|
this.ngZone.run(() => {
|
||||||
this.cd.detectChanges();
|
this.cd.detectChanges();
|
||||||
});*/
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public openToolbar() {
|
public openToolbar() {
|
||||||
@ -731,6 +732,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
const widget = importData.widget;
|
const widget = importData.widget;
|
||||||
const layoutId = importData.layoutId;
|
const layoutId = importData.layoutId;
|
||||||
this.layouts[layoutId].layoutCtx.widgets.addWidgetId(widget.id);
|
this.layouts[layoutId].layoutCtx.widgets.addWidgetId(widget.id);
|
||||||
|
this.runChangeDetection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -885,28 +887,17 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
} else if (this.isAddingWidget) {
|
} else if (this.isAddingWidget) {
|
||||||
this.isAddingWidgetClosed = false;
|
this.isAddingWidgetClosed = false;
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
|
||||||
this.cd.detach();
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
detailsDrawerOpened() {
|
|
||||||
this.cd.reattach();
|
|
||||||
}
|
|
||||||
|
|
||||||
detailsDrawerClosedStart() {
|
|
||||||
this.cd.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detailsDrawerClosed() {
|
detailsDrawerClosed() {
|
||||||
this.isEditingWidgetClosed = true;
|
this.isEditingWidgetClosed = true;
|
||||||
this.isAddingWidgetClosed = true;
|
this.isAddingWidgetClosed = true;
|
||||||
this.cd.reattach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private addWidgetToLayout(widget: Widget, layoutId: DashboardLayoutId) {
|
private addWidgetToLayout(widget: Widget, layoutId: DashboardLayoutId) {
|
||||||
this.dashboardUtils.addWidgetToLayout(this.dashboard, this.dashboardCtx.state, layoutId, widget);
|
this.dashboardUtils.addWidgetToLayout(this.dashboard, this.dashboardCtx.state, layoutId, widget);
|
||||||
this.layouts[layoutId].layoutCtx.widgets.addWidgetId(widget.id);
|
this.layouts[layoutId].layoutCtx.widgets.addWidgetId(widget.id);
|
||||||
|
this.runChangeDetection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private selectTargetLayout(): Observable<DashboardLayoutId> {
|
private selectTargetLayout(): Observable<DashboardLayoutId> {
|
||||||
@ -1060,6 +1051,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
pos, this.entityAliasesUpdated.bind(this), this.filtersUpdated.bind(this)).subscribe(
|
pos, this.entityAliasesUpdated.bind(this), this.filtersUpdated.bind(this)).subscribe(
|
||||||
(widget) => {
|
(widget) => {
|
||||||
layoutCtx.widgets.addWidgetId(widget.id);
|
layoutCtx.widgets.addWidgetId(widget.id);
|
||||||
|
this.runChangeDetection();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1068,6 +1060,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
pos).subscribe(
|
pos).subscribe(
|
||||||
(widget) => {
|
(widget) => {
|
||||||
layoutCtx.widgets.addWidgetId(widget.id);
|
layoutCtx.widgets.addWidgetId(widget.id);
|
||||||
|
this.runChangeDetection();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1086,6 +1079,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
if (res) {
|
if (res) {
|
||||||
if (layoutCtx.widgets.removeWidgetId(widget.id)) {
|
if (layoutCtx.widgets.removeWidgetId(widget.id)) {
|
||||||
this.dashboardUtils.removeWidgetFromLayout(this.dashboard, this.dashboardCtx.state, layoutCtx.id, widget.id);
|
this.dashboardUtils.removeWidgetFromLayout(this.dashboard, this.dashboardCtx.state, layoutCtx.id, widget.id);
|
||||||
|
this.runChangeDetection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AfterViewInit,
|
AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
DoCheck,
|
DoCheck,
|
||||||
Input,
|
Input,
|
||||||
@ -59,7 +59,8 @@ import { UtilsService } from '@core/services/utils.service';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-dashboard',
|
selector: 'tb-dashboard',
|
||||||
templateUrl: './dashboard.component.html',
|
templateUrl: './dashboard.component.html',
|
||||||
styleUrls: ['./dashboard.component.scss']
|
styleUrls: ['./dashboard.component.scss'],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class DashboardComponent extends PageComponent implements IDashboardComponent, DoCheck, OnInit, OnDestroy, AfterViewInit, OnChanges {
|
export class DashboardComponent extends PageComponent implements IDashboardComponent, DoCheck, OnInit, OnDestroy, AfterViewInit, OnChanges {
|
||||||
|
|
||||||
@ -178,6 +179,7 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo
|
|||||||
private breakpointObserver: BreakpointObserver,
|
private breakpointObserver: BreakpointObserver,
|
||||||
private differs: IterableDiffers,
|
private differs: IterableDiffers,
|
||||||
private kvDiffers: KeyValueDiffers,
|
private kvDiffers: KeyValueDiffers,
|
||||||
|
private cd: ChangeDetectorRef,
|
||||||
private ngZone: NgZone) {
|
private ngZone: NgZone) {
|
||||||
super(store);
|
super(store);
|
||||||
this.authUser = getCurrentAuthUser(store);
|
this.authUser = getCurrentAuthUser(store);
|
||||||
@ -249,6 +251,7 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo
|
|||||||
let updateLayoutOpts = false;
|
let updateLayoutOpts = false;
|
||||||
let updateEditingOpts = false;
|
let updateEditingOpts = false;
|
||||||
let updateWidgets = false;
|
let updateWidgets = false;
|
||||||
|
let updateDashboardTimewindow = false;
|
||||||
for (const propName of Object.keys(changes)) {
|
for (const propName of Object.keys(changes)) {
|
||||||
const change = changes[propName];
|
const change = changes[propName];
|
||||||
if (!change.firstChange && change.currentValue !== change.previousValue) {
|
if (!change.firstChange && change.currentValue !== change.previousValue) {
|
||||||
@ -261,13 +264,16 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo
|
|||||||
} else if (['widgets', 'widgetLayouts'].includes(propName)) {
|
} else if (['widgets', 'widgetLayouts'].includes(propName)) {
|
||||||
updateWidgets = true;
|
updateWidgets = true;
|
||||||
} else if (propName === 'dashboardTimewindow') {
|
} else if (propName === 'dashboardTimewindow') {
|
||||||
this.dashboardTimewindowChangedSubject.next(this.dashboardTimewindow);
|
updateDashboardTimewindow = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updateWidgets) {
|
if (updateWidgets) {
|
||||||
this.updateWidgets();
|
this.updateWidgets();
|
||||||
|
} else if (updateDashboardTimewindow) {
|
||||||
|
this.dashboardTimewindowChangedSubject.next(this.dashboardTimewindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateMobileOpts) {
|
if (updateMobileOpts) {
|
||||||
this.updateMobileOpts();
|
this.updateMobileOpts();
|
||||||
}
|
}
|
||||||
@ -528,6 +534,10 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo
|
|||||||
this.updateWidgetLayouts();
|
this.updateWidgetLayouts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public detectChanges() {
|
||||||
|
this.cd.detectChanges();
|
||||||
|
}
|
||||||
|
|
||||||
private detectRowSize(isMobile: boolean, autofillHeight: boolean, parentHeight?: number): number | null {
|
private detectRowSize(isMobile: boolean, autofillHeight: boolean, parentHeight?: number): number | null {
|
||||||
let rowHeight = null;
|
let rowHeight = null;
|
||||||
if (!autofillHeight) {
|
if (!autofillHeight) {
|
||||||
|
|||||||
@ -468,10 +468,13 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private detectChanges() {
|
private detectChanges(detectDashboardChanges = false) {
|
||||||
if (!this.destroyed) {
|
if (!this.destroyed) {
|
||||||
try {
|
try {
|
||||||
this.cd.detectChanges();
|
this.cd.detectChanges();
|
||||||
|
if (detectDashboardChanges) {
|
||||||
|
this.widgetContext.dashboard.detectChanges();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// console.log(e);
|
// console.log(e);
|
||||||
}
|
}
|
||||||
@ -491,6 +494,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
if (!this.widgetContext.inited && this.isReady()) {
|
if (!this.widgetContext.inited && this.isReady()) {
|
||||||
this.widgetContext.inited = true;
|
this.widgetContext.inited = true;
|
||||||
|
this.widgetContext.dashboard.detectChanges();
|
||||||
if (this.cafs.init) {
|
if (this.cafs.init) {
|
||||||
this.cafs.init();
|
this.cafs.init();
|
||||||
this.cafs.init = null;
|
this.cafs.init = null;
|
||||||
@ -878,7 +882,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
timeWindowUpdated: (subscription, timeWindowConfig) => {
|
timeWindowUpdated: (subscription, timeWindowConfig) => {
|
||||||
this.ngZone.run(() => {
|
this.ngZone.run(() => {
|
||||||
this.widget.config.timewindow = timeWindowConfig;
|
this.widget.config.timewindow = timeWindowConfig;
|
||||||
this.detectChanges();
|
this.detectChanges(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -79,6 +79,7 @@ export interface IDashboardComponent {
|
|||||||
pauseChangeNotifications();
|
pauseChangeNotifications();
|
||||||
resumeChangeNotifications();
|
resumeChangeNotifications();
|
||||||
notifyLayoutUpdated();
|
notifyLayoutUpdated();
|
||||||
|
detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
declare type DashboardWidgetUpdateOperation = 'add' | 'remove' | 'update';
|
declare type DashboardWidgetUpdateOperation = 'add' | 'remove' | 'update';
|
||||||
@ -342,7 +343,7 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget {
|
|||||||
widget.id = guid();
|
widget.id = guid();
|
||||||
}
|
}
|
||||||
this.widgetId = widget.id;
|
this.widgetId = widget.id;
|
||||||
this.updateWidgetParams();
|
this.updateWidgetParams(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
gridsterItemComponent$(): Observable<GridsterItemComponentInterface> {
|
gridsterItemComponent$(): Observable<GridsterItemComponentInterface> {
|
||||||
@ -353,7 +354,7 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateWidgetParams() {
|
updateWidgetParams(detectChanges = true) {
|
||||||
this.color = this.widget.config.color || 'rgba(0, 0, 0, 0.87)';
|
this.color = this.widget.config.color || 'rgba(0, 0, 0, 0.87)';
|
||||||
this.backgroundColor = this.widget.config.backgroundColor || '#fff';
|
this.backgroundColor = this.widget.config.backgroundColor || '#fff';
|
||||||
this.padding = this.widget.config.padding || '8px';
|
this.padding = this.widget.config.padding || '8px';
|
||||||
@ -405,6 +406,9 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget {
|
|||||||
|
|
||||||
this.customHeaderActions = this.widgetContext.customHeaderActions ? this.widgetContext.customHeaderActions : [];
|
this.customHeaderActions = this.widgetContext.customHeaderActions ? this.widgetContext.customHeaderActions : [];
|
||||||
this.widgetActions = this.widgetContext.widgetActions ? this.widgetContext.widgetActions : [];
|
this.widgetActions = this.widgetContext.widgetActions ? this.widgetContext.widgetActions : [];
|
||||||
|
if (detectChanges) {
|
||||||
|
this.dashboard.detectChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@enumerable(true)
|
@enumerable(true)
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
Inject,
|
Inject,
|
||||||
@ -158,6 +159,7 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
|
|||||||
private millisecondsToTimeStringPipe: MillisecondsToTimeStringPipe,
|
private millisecondsToTimeStringPipe: MillisecondsToTimeStringPipe,
|
||||||
private datePipe: DatePipe,
|
private datePipe: DatePipe,
|
||||||
private overlay: Overlay,
|
private overlay: Overlay,
|
||||||
|
private cd: ChangeDetectorRef,
|
||||||
public viewContainerRef: ViewContainerRef,
|
public viewContainerRef: ViewContainerRef,
|
||||||
public breakpointObserver: BreakpointObserver,
|
public breakpointObserver: BreakpointObserver,
|
||||||
@Inject(DOCUMENT) private document: Document,
|
@Inject(DOCUMENT) private document: Document,
|
||||||
@ -313,6 +315,7 @@ export class TimewindowComponent implements OnInit, OnDestroy, ControlValueAcces
|
|||||||
} else {
|
} else {
|
||||||
this.innerValue.displayTimezoneAbbr = '';
|
this.innerValue.displayTimezoneAbbr = '';
|
||||||
}
|
}
|
||||||
|
this.cd.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
hideLabel() {
|
hideLabel() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user