Skip to content

Commit

Permalink
refactor(module:calendar): remove used listener and improve perf (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
trotyl authored and vthinkxie committed Mar 11, 2018
1 parent ca79b0e commit 4f9e550
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/calendar/nz-calendar-header.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<nz-select class="ant-fullcalendar--year-select" [nzSize]="size"
[(ngModel)]="activeYear" (ngModelChange)="yearChange.emit($event)">
[ngModel]="activeYear" (ngModelChange)="yearChange.emit($event)">
<nz-option *ngFor="let year of years" [nzLabel]="year.label" [nzValue]="year.value"></nz-option>
</nz-select>

<nz-select *ngIf="mode === 'month'" class="ant-fullcalendar--year-select" [nzSize]="size"
[(ngModel)]="activeMonth" (ngModelChange)="monthChange.emit($event)">
[ngModel]="activeMonth" (ngModelChange)="monthChange.emit($event)">
<nz-option *ngFor="let month of months" [nzLabel]="month.label" [nzValue]="month.value"></nz-option>
</nz-select>

Expand Down
6 changes: 4 additions & 2 deletions components/calendar/nz-calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,15 @@ export class NzCalendarComponent implements ControlValueAccessor, OnInit {
}

private updateDate(date: Date, touched: boolean = true): void {
const dayChanged = !isSameDay(date, this.activeDate);
const monthChanged = !isSameMonth(date, this.activeDate);
const yearChanged = !isSameYear(date, this.activeDate);

this.activeDate = date;

if (dayChanged) {
this.calculateActiveDate();
}
if (monthChanged) {
this.setUpDateMatrix();
this.calculateCurrentDate();
Expand All @@ -152,8 +156,6 @@ export class NzCalendarComponent implements ControlValueAccessor, OnInit {
this.calculateCurrentMonth();
}

this.calculateActiveDate();

if (touched) {
this.onChangeFn(date);
this.onTouchFn();
Expand Down

0 comments on commit 4f9e550

Please sign in to comment.