|
10 | 10 | * granted to it by virtue of its status as an Intergovernmental Organization |
11 | 11 | * or submit itself to any jurisdiction. |
12 | 12 | */ |
13 | | -import { Observable } from '/js/src/index.js'; |
| 13 | +import { FilterModel } from '../FilterModel'; |
14 | 14 |
|
15 | 15 | /** |
16 | 16 | * Model for a generic filter input |
17 | 17 | */ |
18 | | -export class FilterInputModel extends Observable { |
| 18 | +export class FilterInputModel extends FilterModel { |
19 | 19 | /** |
20 | 20 | * Constructor |
| 21 | + * |
| 22 | + * @param {callback} parse function called to parse a value from a raw value |
21 | 23 | */ |
22 | | - constructor() { |
| 24 | + constructor(parse) { |
23 | 25 | super(); |
24 | 26 |
|
| 27 | + this.parse = parse; |
25 | 28 | this._value = null; |
26 | 29 | this._raw = ''; |
27 | | - |
28 | | - this._visualChange$ = new Observable(); |
29 | 30 | } |
30 | 31 |
|
31 | 32 | /** |
32 | 33 | * Define the current value of the filter |
33 | 34 | * |
34 | 35 | * @param {string} raw the raw value of the filter |
| 36 | + * @override |
35 | 37 | * @return {void} |
36 | 38 | */ |
37 | 39 | update(raw) { |
38 | | - const previousValues = this.value; |
39 | | - |
40 | | - this._value = this.valueFromRaw(raw); |
41 | | - this._raw = raw; |
| 40 | + const value = this._parse(raw); |
42 | 41 |
|
43 | | - if (this.areValuesEquals(this.value, previousValues)) { |
44 | | - // Only raw value changed |
45 | | - this._visualChange$.notify(); |
46 | | - } else { |
| 42 | + if (!this.areValuesEquals(this._value, value)) { |
| 43 | + this._value = value; |
47 | 44 | this.notify(); |
48 | 45 | } |
49 | 46 | } |
50 | 47 |
|
51 | 48 | /** |
52 | | - * Reset the filter to its default value |
53 | | - * |
54 | | - * @return {void} |
| 49 | + * @inheritdoc |
55 | 50 | */ |
56 | 51 | reset() { |
57 | 52 | this._value = null; |
@@ -86,23 +81,10 @@ export class FilterInputModel extends Observable { |
86 | 81 | } |
87 | 82 |
|
88 | 83 | /** |
89 | | - * Returns the observable notified any time there is a visual change which has no impact on the actual filter value |
90 | | - * |
91 | | - * @return {Observable} the observable |
92 | | - */ |
93 | | - get visualChange$() { |
94 | | - return this._visualChange$; |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * Returns the processed value from raw input |
99 | | - * |
100 | | - * @param {string} raw the raw input value |
101 | | - * @return {*} the processed value |
102 | | - * @protected |
| 84 | + * @inheritdoc |
103 | 85 | */ |
104 | | - valueFromRaw(raw) { |
105 | | - return raw.trim(); |
| 86 | + get normalized() { |
| 87 | + return this.value; |
106 | 88 | } |
107 | 89 |
|
108 | 90 | /** |
|
0 commit comments