Skip to content

Commit 2fb7073

Browse files
authoredDec 21, 2017
Push (#324)
* time select adding onPush * adding , * adding on push to day-time-calendar * adding more on push * fixing unit test * fixing e2e
1 parent 728b342 commit 2fb7073

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed
 

‎src/app/date-picker/date-picker.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DatePickerComponent} from './date-picker.component';
22

33
describe('Component: DpDayPicker', () => {
4-
const component = new DatePickerComponent(null, null, null, null, null);
4+
const component = new DatePickerComponent(null, null, null, null, null, null);
55

66
it('should create an instance', () => {
77
expect(component).toBeTruthy();

‎src/app/date-picker/date-picker.component.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {IDatePickerConfig, IDatePickerConfigInternal} from './date-picker-config
1818
import {IDpDayPickerApi} from './date-picker.api';
1919
import {DatePickerService} from './date-picker.service';
2020
import {
21-
AfterViewInit,
21+
AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef,
2222
Component,
2323
ElementRef,
2424
EventEmitter,
@@ -53,6 +53,7 @@ import {DayTimeCalendarComponent} from '../day-time-calendar/day-time-calendar.c
5353
templateUrl: 'date-picker.component.html',
5454
styleUrls: ['date-picker.component.less'],
5555
encapsulation: ViewEncapsulation.None,
56+
changeDetection: ChangeDetectionStrategy.OnPush,
5657
providers: [
5758
DatePickerService,
5859
DayTimeCalendarService,
@@ -191,7 +192,8 @@ export class DatePickerComponent implements OnChanges,
191192
private domHelper: DomHelper,
192193
private elemRef: ElementRef,
193194
private renderer: Renderer,
194-
private utilsService: UtilsService) {
195+
private utilsService: UtilsService,
196+
public cd: ChangeDetectorRef) {
195197
}
196198

197199
@HostListener('click')
@@ -240,6 +242,8 @@ export class DatePickerComponent implements OnChanges,
240242
} else {
241243
this.selected = [];
242244
}
245+
246+
this.cd.markForCheck();
243247
}
244248

245249
registerOnChange(fn: any): void {
@@ -382,6 +386,7 @@ export class DatePickerComponent implements OnChanges,
382386
}
383387

384388
this.open.emit();
389+
this.cd.markForCheck();
385390
}
386391

387392
hideCalendar() {
@@ -392,6 +397,7 @@ export class DatePickerComponent implements OnChanges,
392397
}
393398

394399
this.close.emit();
400+
this.cd.markForCheck();
395401
}
396402

397403
onViewDateChange(value: string) {

‎src/app/date-picker/date-picker.directive.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
ViewContainerRef
1717
} from '@angular/core';
1818
import {NgControl} from '@angular/forms';
19-
import {Moment} from 'moment';
2019
import {CalendarValue} from '../common/types/calendar-value';
2120
import {SingleCalendarValue} from '../common/types/single-calendar-value';
2221

@@ -43,6 +42,7 @@ export class DatePickerDirective implements OnInit {
4342
@Input('dpDayPicker') set config(config: IDatePickerDirectiveConfig) {
4443
this._config = this.service.getConfig(config, this.viewContainerRef.element, this.attachTo);
4544
this.updateDatepickerConfig();
45+
this.markForCheck();
4646
}
4747

4848
get attachTo(): ElementRef | string {
@@ -53,6 +53,7 @@ export class DatePickerDirective implements OnInit {
5353
this._attachTo = attachTo;
5454
this._config = this.service.getConfig(this.config, this.viewContainerRef.element, this.attachTo);
5555
this.updateDatepickerConfig();
56+
this.markForCheck();
5657
}
5758

5859
get theme(): string {
@@ -64,6 +65,8 @@ export class DatePickerDirective implements OnInit {
6465
if (this.datePicker) {
6566
this.datePicker.theme = theme;
6667
}
68+
69+
this.markForCheck();
6770
}
6871

6972
get mode(): CalendarMode {
@@ -75,6 +78,8 @@ export class DatePickerDirective implements OnInit {
7578
if (this.datePicker) {
7679
this.datePicker.mode = mode;
7780
}
81+
82+
this.markForCheck();
7883
}
7984

8085
@Input() set minDate(minDate: SingleCalendarValue) {
@@ -83,6 +88,8 @@ export class DatePickerDirective implements OnInit {
8388
this.datePicker.minDate = minDate;
8489
this.datePicker.ngOnInit();
8590
}
91+
92+
this.markForCheck();
8693
}
8794

8895
get minDate(): SingleCalendarValue {
@@ -95,6 +102,8 @@ export class DatePickerDirective implements OnInit {
95102
this.datePicker.maxDate = maxDate;
96103
this.datePicker.ngOnInit();
97104
}
105+
106+
this.markForCheck();
98107
}
99108

100109
get maxDate(): SingleCalendarValue {
@@ -107,6 +116,8 @@ export class DatePickerDirective implements OnInit {
107116
this.datePicker.minTime = minTime;
108117
this.datePicker.ngOnInit();
109118
}
119+
120+
this.markForCheck();
110121
}
111122

112123
get minTime(): SingleCalendarValue {
@@ -119,6 +130,8 @@ export class DatePickerDirective implements OnInit {
119130
this.datePicker.maxTime = maxTime;
120131
this.datePicker.ngOnInit();
121132
}
133+
134+
this.markForCheck();
122135
}
123136

124137
get maxTime(): SingleCalendarValue {
@@ -132,6 +145,8 @@ export class DatePickerDirective implements OnInit {
132145
@Input() set displayDate(displayDate: SingleCalendarValue) {
133146
this._displayDate = displayDate;
134147
this.updateDatepickerConfig();
148+
149+
this.markForCheck();
135150
}
136151

137152
@Output() open = new EventEmitter<void>();
@@ -241,4 +256,10 @@ export class DatePickerDirective implements OnInit {
241256
}
242257
}
243258
}
259+
260+
markForCheck() {
261+
if (this.datePicker) {
262+
this.datePicker.cd.markForCheck();
263+
}
264+
}
244265
}

‎src/app/day-time-calendar/day-time-calendar.component.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import {ECalendarValue} from '../common/types/calendar-value-enum';
22
import {SingleCalendarValue} from '../common/types/single-calendar-value';
33
import {
4+
ChangeDetectionStrategy,
5+
ChangeDetectorRef,
46
Component,
57
EventEmitter,
68
forwardRef,
79
HostBinding,
810
Input,
911
OnChanges,
1012
OnInit,
11-
Output, SimpleChange,
12-
SimpleChanges, ViewChild,
13+
Output,
14+
SimpleChanges,
15+
ViewChild,
1316
ViewEncapsulation
1417
} from '@angular/core';
1518
import {
@@ -35,6 +38,7 @@ import {DayCalendarComponent} from '../day-calendar/day-calendar.component';
3538
selector: 'dp-day-time-calendar',
3639
templateUrl: 'day-time-calendar.component.html',
3740
styleUrls: ['day-time-calendar.component.less'],
41+
changeDetection: ChangeDetectionStrategy.OnPush,
3842
encapsulation: ViewEncapsulation.None,
3943
providers: [
4044
DayTimeCalendarService,
@@ -81,7 +85,8 @@ export class DayTimeCalendarComponent implements OnInit, OnChanges, ControlValue
8185
}
8286

8387
constructor(public dayTimeCalendarService: DayTimeCalendarService,
84-
public utilsService: UtilsService) {
88+
public utilsService: UtilsService,
89+
public cd: ChangeDetectorRef) {
8590
}
8691

8792
ngOnInit() {
@@ -117,6 +122,8 @@ export class DayTimeCalendarComponent implements OnInit, OnChanges, ControlValue
117122
} else {
118123
this.selected = null;
119124
}
125+
126+
this.cd.markForCheck();
120127
}
121128

122129
registerOnChange(fn: any): void {

‎src/app/time-select/time-select.component.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {ECalendarValue} from '../common/types/calendar-value-enum';
22
import {SingleCalendarValue} from '../common/types/single-calendar-value';
33
import {
4+
ChangeDetectionStrategy,
5+
ChangeDetectorRef,
46
Component,
57
EventEmitter,
68
forwardRef,
@@ -34,6 +36,7 @@ import {DateValidator} from '../common/types/validator.type';
3436
templateUrl: 'time-select.component.html',
3537
styleUrls: ['time-select.component.less'],
3638
encapsulation: ViewEncapsulation.None,
39+
changeDetection: ChangeDetectionStrategy.OnPush,
3740
providers: [
3841
TimeSelectService,
3942
{
@@ -106,7 +109,8 @@ export class TimeSelectComponent implements OnInit, OnChanges, ControlValueAcces
106109
};
107110

108111
constructor(public timeSelectService: TimeSelectService,
109-
public utilsService: UtilsService) {
112+
public utilsService: UtilsService,
113+
public cd: ChangeDetectorRef) {
110114
}
111115

112116
ngOnInit() {
@@ -144,6 +148,8 @@ export class TimeSelectComponent implements OnInit, OnChanges, ControlValueAcces
144148
.getInputType(this.inputValue, false);
145149
}
146150
}
151+
152+
this.cd.markForCheck();
147153
}
148154

149155
registerOnChange(fn: any): void {
@@ -201,6 +207,7 @@ export class TimeSelectComponent implements OnInit, OnChanges, ControlValueAcces
201207

202208
emitChange() {
203209
this.onChange.emit({date: this.selected, selected: false});
210+
this.cd.markForCheck();
204211
}
205212

206213
calculateTimeParts(time: Moment) {

0 commit comments

Comments
 (0)
Please sign in to comment.