Skip to content

Commit 8dc7d2a

Browse files
roboshoesjelbourn
authored andcommitted
Observable in MatDateSelection (#13037)
This change adds an observable to the date selection. This allows the usage of a single date selection instance instead of creating multiple.
1 parent 3a1442d commit 8dc7d2a

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/lib/core/datetime/date-selection.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
*/
88

99
import {DateAdapter} from '@angular/material/core';
10+
import {Subject} from 'rxjs';
1011

1112
export abstract class MatDateSelection<D> {
13+
valueChanges = new Subject<void>();
14+
1215
constructor(protected readonly adapter: DateAdapter<D>) {}
1316

17+
dispose() {
18+
this.valueChanges.complete();
19+
}
20+
1421
abstract add(date: D): void;
1522
abstract clone(): MatDateSelection<D>;
1623
abstract getFirstSelectedDate(): D|null;
@@ -41,16 +48,11 @@ export class MatSingleDateSelection<D> extends MatDateSelection<D> {
4148

4249
add(date: D) {
4350
this.date = date;
51+
this.valueChanges.next();
4452
}
4553

4654
clone(): MatDateSelection<D> {
47-
const copy = new MatSingleDateSelection<D>(this.adapter);
48-
49-
if (this.date) {
50-
copy.add(this.adapter.clone(this.date));
51-
}
52-
53-
return copy as MatDateSelection<D>;
55+
return new MatSingleDateSelection<D>(this.adapter, this.date);
5456
}
5557

5658
getFirstSelectedDate() { return this.date; }
@@ -107,21 +109,13 @@ export class MatRangeDateSelection<D> extends MatDateSelection<D> {
107109
this.start = date;
108110
this.end = null;
109111
}
112+
113+
this.valueChanges.next();
110114
}
111115

112116

113117
clone(): MatDateSelection<D> {
114-
const copy = new MatRangeDateSelection<D>(this.adapter);
115-
116-
if (this.start) {
117-
copy.setFirstSelectedDate(this.adapter.clone(this.start));
118-
}
119-
120-
if (this.end) {
121-
copy.setLastSelectedDate(this.adapter.clone(this.end));
122-
}
123-
124-
return copy as MatDateSelection<D>;
118+
return new MatRangeDateSelection<D>(this.adapter, this.start, this.end);
125119
}
126120

127121
getFirstSelectedDate() { return this.start; }

0 commit comments

Comments
 (0)