Skip to content

Commit

Permalink
refactor(module:calendar): use OnPush by default (#2825)
Browse files Browse the repository at this point in the history
ref #2381
  • Loading branch information
wilsoncook authored and vthinkxie committed Feb 11, 2019
1 parent e121bd3 commit 05ce186
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion components/calendar/nz-calendar-header.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import setMonth from 'date-fns/set_month';
import { NzI18nService as I18n } from '../i18n/nz-i18n.service';

@Component({
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
selector : 'nz-calendar-header',
templateUrl: './nz-calendar-header.component.html',
host : {
Expand Down
7 changes: 5 additions & 2 deletions components/calendar/nz-calendar.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { forwardRef, Component, ContentChild, EventEmitter, HostBinding, Input, OnInit, Output, TemplateRef } from '@angular/core';
import { forwardRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, EventEmitter, HostBinding, Input, OnInit, Output, TemplateRef, ViewEncapsulation } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import addDays from 'date-fns/add_days';
import differenceInCalendarDays from 'date-fns/difference_in_calendar_days';
Expand All @@ -20,6 +20,8 @@ import { NzI18nService as I18n } from '../i18n/nz-i18n.service';
import { NzDateCellDirective as DateCell, NzDateFullCellDirective as DateFullCell, NzMonthCellDirective as MonthCell, NzMonthFullCellDirective as MonthFullCell } from './nz-calendar-cells';

@Component({
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'nz-calendar',
templateUrl: './nz-calendar.component.html',
providers: [
Expand Down Expand Up @@ -94,7 +96,7 @@ export class NzCalendarComponent implements ControlValueAccessor, OnInit {
return startOfWeek(startOfMonth(this.activeDate));
}

constructor(private i18n: I18n) { }
constructor(private i18n: I18n, private cdr: ChangeDetectorRef) { }

ngOnInit(): void {
this.setUpDaysInWeek();
Expand Down Expand Up @@ -126,6 +128,7 @@ export class NzCalendarComponent implements ControlValueAccessor, OnInit {

writeValue(value: Date|null): void {
this.updateDate(value || new Date(), false);
this.cdr.markForCheck();
}

registerOnChange(fn: (date: Date) => void): void {
Expand Down

0 comments on commit 05ce186

Please sign in to comment.