Skip to content

Commit

Permalink
fix(sidebar): toggle performance issues (#5658)
Browse files Browse the repository at this point in the history
* refactor: improve observable layout change sharing
* feat: add safe delayed event of layout change
* fix: replace change layout with safe change
* fix: limit front card width to prevent map overflow before repaint
  • Loading branch information
sashaqred authored Apr 15, 2020
1 parent 5cc4c19 commit 9eaf0bb
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 23 deletions.
14 changes: 10 additions & 4 deletions src/app/@core/utils/layout.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { delay, share } from 'rxjs/operators';
import { delay, shareReplay, debounceTime } from 'rxjs/operators';

@Injectable()
export class LayoutService {

protected layoutSize$ = new Subject();
protected layoutSizeChange$ = this.layoutSize$.pipe(
shareReplay({ refCount: true }),
);

changeLayoutSize() {
this.layoutSize$.next();
}

onChangeLayoutSize(): Observable<any> {
return this.layoutSize$.pipe(
share(),
delay(1),
return this.layoutSizeChange$.pipe(delay(1));
}

onSafeChangeLayoutSize(): Observable<any> {
return this.layoutSizeChange$.pipe(
debounceTime(350),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ElectricityChartComponent implements AfterViewInit, OnDestroy {

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/dashboard/traffic/traffic-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class TrafficChartComponent implements AfterViewInit, OnDestroy {

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OrdersChartComponent implements AfterViewInit, OnDestroy, OnChanges

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ProfitChartComponent implements AfterViewInit, OnDestroy, OnChanges

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class CountryOrdersChartComponent implements AfterViewInit, OnDestroy, On

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class EarningLiveUpdateChartComponent implements AfterViewInit, OnDestroy

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class StatsAreaChartComponent implements AfterViewInit, OnDestroy {

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class StatsBarAnimationChartComponent implements AfterViewInit, OnDestroy

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
22 changes: 14 additions & 8 deletions src/app/pages/e-commerce/profit-card/profit-card.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@
cursor: pointer;
}

::ng-deep .flipped {
.back-container {
.flip-icon {
transform: scaleX(-1);
}
::ng-deep {
.front-container {
max-width: 100%;
}

.front-container {
.flip-icon {
display: none;
.flipped {
.back-container {
.flip-icon {
transform: scaleX(-1);
}
}

.front-container {
.flip-icon {
display: none;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class TrafficBarChartComponent implements AfterViewInit, OnDestroy, OnCha

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ECommerceVisitorsAnalyticsChartComponent implements AfterViewInit,

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ECommerceVisitorsStatisticsComponent implements AfterViewInit, OnDe

constructor(private theme: NbThemeService,
private layoutService: LayoutService) {
this.layoutService.onChangeLayoutSize()
this.layoutService.onSafeChangeLayoutSize()
.pipe(
takeWhile(() => this.alive),
)
Expand Down

0 comments on commit 9eaf0bb

Please sign in to comment.