Skip to content

Commit

Permalink
perf(module:carousel): do not run change detection when the timer fir…
Browse files Browse the repository at this point in the history
…es (#7136)
  • Loading branch information
arturovt committed Feb 25, 2022
1 parent 7acb8db commit fc991d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/carousel/carousel.component.ts
Expand Up @@ -172,7 +172,7 @@ export class NzCarouselComponent implements AfterContentInit, AfterViewInit, OnD
constructor(
elementRef: ElementRef,
public readonly nzConfigService: NzConfigService,
private readonly ngZone: NgZone,
public readonly ngZone: NgZone,
private readonly renderer: Renderer2,
private readonly cdr: ChangeDetectorRef,
private readonly platform: Platform,
Expand Down
7 changes: 5 additions & 2 deletions components/carousel/strategies/experimental/flip-strategy.ts
Expand Up @@ -28,8 +28,11 @@ export class NzCarouselFlipStrategy extends NzCarouselBaseStrategy {
this.renderer.setStyle(content.el, 'backface-visibility', 'hidden');
});

timer(this.carouselComponent!.nzTransitionSpeed).subscribe(() => {
this.contents.forEach(c => this.renderer.setStyle(c.el, 'transition', ['transform 500ms ease 0s']));
const { carouselComponent } = this;
carouselComponent!.ngZone.runOutsideAngular(() => {
timer(carouselComponent!.nzTransitionSpeed).subscribe(() => {
this.contents.forEach(c => this.renderer.setStyle(c.el, 'transition', ['transform 500ms ease 0s']));
});
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/carousel/typings.ts
Expand Up @@ -4,7 +4,7 @@
*/

import { Direction } from '@angular/cdk/bidi';
import { InjectionToken, QueryList } from '@angular/core';
import { InjectionToken, NgZone, QueryList } from '@angular/core';

import { NzCarouselContentDirective } from './carousel-content.directive';
import { NzCarouselBaseStrategy } from './strategies/base-strategy';
Expand All @@ -21,6 +21,7 @@ export interface NzCarouselComponentAsSource {
slickTrackEl: HTMLElement;
activeIndex: number;
dir: Direction;
ngZone: NgZone;
}

export interface NzCarouselStrategyRegistryItem {
Expand Down

0 comments on commit fc991d1

Please sign in to comment.