Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(module:carousel): do not run change detection when the timer fires #7136

Merged
merged 1 commit into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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