Skip to content

Commit

Permalink
refactor(sidebar): use OnPush change detection strategy (#2646)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Added change detector ref constructor parameter.
  • Loading branch information
yggg authored Jan 18, 2021
1 parent 8a35e85 commit 59daeea
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/framework/theme/components/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { Component, HostBinding, Input, OnInit, OnDestroy, ElementRef, Output, EventEmitter } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
HostBinding,
Input,
OnDestroy,
OnInit,
Output,
} from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil, filter } from 'rxjs/operators';

Expand Down Expand Up @@ -131,6 +142,7 @@ export class NbSidebarFooterComponent {
<ng-content select="nb-sidebar-footer"></ng-content>
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NbSidebarComponent implements OnInit, OnDestroy {

Expand Down Expand Up @@ -295,10 +307,12 @@ export class NbSidebarComponent implements OnInit, OnDestroy {
*/
@Output() readonly responsiveStateChange = new EventEmitter<NbSidebarResponsiveState>();

constructor(private sidebarService: NbSidebarService,
constructor(
private sidebarService: NbSidebarService,
private themeService: NbThemeService,
private element: ElementRef) {
}
private element: ElementRef,
private cd: ChangeDetectorRef,
) {}

ngOnInit() {
this.sidebarService.onToggle()
Expand Down Expand Up @@ -364,6 +378,7 @@ export class NbSidebarComponent implements OnInit, OnDestroy {
collapse() {
this.state = 'collapsed';
this.stateChange.emit(this.state);
this.cd.markForCheck();
}

/**
Expand All @@ -372,6 +387,7 @@ export class NbSidebarComponent implements OnInit, OnDestroy {
expand() {
this.state = 'expanded';
this.stateChange.emit(this.state);
this.cd.markForCheck();
}

/**
Expand All @@ -380,6 +396,7 @@ export class NbSidebarComponent implements OnInit, OnDestroy {
compact() {
this.state = 'compacted';
this.stateChange.emit(this.state);
this.cd.markForCheck();
}

/**
Expand All @@ -406,6 +423,7 @@ export class NbSidebarComponent implements OnInit, OnDestroy {
this.state = compact ? 'compacted' : 'collapsed';
}
this.stateChange.emit(this.state);
this.cd.markForCheck();
}

protected subscribeToMediaQueryChange() {
Expand Down Expand Up @@ -440,6 +458,7 @@ export class NbSidebarComponent implements OnInit, OnDestroy {
if (newResponsiveState && newResponsiveState !== this.responsiveState) {
this.responsiveState = newResponsiveState;
this.responsiveStateChange.emit(this.responsiveState);
this.cd.markForCheck();
}
});
}
Expand Down

0 comments on commit 59daeea

Please sign in to comment.