|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import {DateAdapter} from '@angular/material/core'; |
| 10 | +import {Subject} from 'rxjs'; |
10 | 11 |
|
11 | 12 | export abstract class MatDateSelection<D> { |
| 13 | + valueChanges = new Subject<void>(); |
| 14 | + |
12 | 15 | constructor(protected readonly adapter: DateAdapter<D>) {} |
13 | 16 |
|
| 17 | + dispose() { |
| 18 | + this.valueChanges.complete(); |
| 19 | + } |
| 20 | + |
14 | 21 | abstract add(date: D): void; |
15 | 22 | abstract clone(): MatDateSelection<D>; |
16 | 23 | abstract getFirstSelectedDate(): D|null; |
@@ -41,16 +48,11 @@ export class MatSingleDateSelection<D> extends MatDateSelection<D> { |
41 | 48 |
|
42 | 49 | add(date: D) { |
43 | 50 | this.date = date; |
| 51 | + this.valueChanges.next(); |
44 | 52 | } |
45 | 53 |
|
46 | 54 | 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); |
54 | 56 | } |
55 | 57 |
|
56 | 58 | getFirstSelectedDate() { return this.date; } |
@@ -107,21 +109,13 @@ export class MatRangeDateSelection<D> extends MatDateSelection<D> { |
107 | 109 | this.start = date; |
108 | 110 | this.end = null; |
109 | 111 | } |
| 112 | + |
| 113 | + this.valueChanges.next(); |
110 | 114 | } |
111 | 115 |
|
112 | 116 |
|
113 | 117 | 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); |
125 | 119 | } |
126 | 120 |
|
127 | 121 | getFirstSelectedDate() { return this.start; } |
|
0 commit comments