From e28411049b3c7c5a83b3e19bf43b4aea6496aa4d Mon Sep 17 00:00:00 2001 From: Max Okorokov Date: Fri, 15 Nov 2019 15:33:58 +0100 Subject: [PATCH] fix(datepicker): don't update public state on each CD --- src/datepicker/datepicker.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/datepicker/datepicker.ts b/src/datepicker/datepicker.ts index 7463493442..37098ea51d 100644 --- a/src/datepicker/datepicker.ts +++ b/src/datepicker/datepicker.ts @@ -153,11 +153,11 @@ export interface NgbDatepickerState { export class NgbDatepicker implements OnDestroy, OnChanges, OnInit, AfterViewInit, ControlValueAccessor { model: DatepickerViewModel; - publicState: NgbDatepickerState = Object.create({}); @ViewChild('months', {static: true}) private _monthsEl: ElementRef; private _controlValue: NgbDate; private _destroyed$ = new Subject(); + private _publicState: NgbDatepickerState = {}; /** * The reference to a custom template for the day. @@ -292,6 +292,15 @@ export class NgbDatepicker implements OnDestroy, const newDate = model.firstDate; const oldDate = this.model ? this.model.firstDate : null; + // update public state + this._publicState = { + maxDate: model.maxDate, + minDate: model.minDate, + firstDate: model.firstDate, + lastDate: model.lastDate, + focusedDate: model.focusDate + }; + let navigationPrevented = false; // emitting navigation event if the first month changes if (!newDate.equals(oldDate)) { @@ -333,16 +342,7 @@ export class NgbDatepicker implements OnDestroy, /** * Returns a copy of the state of the datepicker. */ - get state(): NgbDatepickerState { - Object.assign(this.publicState, { - maxDate: this.model.maxDate, - minDate: this.model.minDate, - firstDate: this.model.firstDate, - lastDate: this.model.lastDate, - focusDate: this.model.focusDate, - }); - return this.publicState; - } + get state(): NgbDatepickerState { return this._publicState; } /** * Focuses on given date.