Skip to content

Commit 9faffaf

Browse files
author
Guust
committed
Make filterInputModel extend filterModel
1 parent f161cae commit 9faffaf

1 file changed

Lines changed: 14 additions & 32 deletions

File tree

lib/public/components/Filters/common/filters/FilterInputModel.js

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,43 @@
1010
* granted to it by virtue of its status as an Intergovernmental Organization
1111
* or submit itself to any jurisdiction.
1212
*/
13-
import { Observable } from '/js/src/index.js';
13+
import { FilterModel } from '../FilterModel';
1414

1515
/**
1616
* Model for a generic filter input
1717
*/
18-
export class FilterInputModel extends Observable {
18+
export class FilterInputModel extends FilterModel {
1919
/**
2020
* Constructor
21+
*
22+
* @param {callback} parse function called to parse a value from a raw value
2123
*/
22-
constructor() {
24+
constructor(parse) {
2325
super();
2426

27+
this.parse = parse;
2528
this._value = null;
2629
this._raw = '';
27-
28-
this._visualChange$ = new Observable();
2930
}
3031

3132
/**
3233
* Define the current value of the filter
3334
*
3435
* @param {string} raw the raw value of the filter
36+
* @override
3537
* @return {void}
3638
*/
3739
update(raw) {
38-
const previousValues = this.value;
39-
40-
this._value = this.valueFromRaw(raw);
41-
this._raw = raw;
40+
const value = this._parse(raw);
4241

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;
4744
this.notify();
4845
}
4946
}
5047

5148
/**
52-
* Reset the filter to its default value
53-
*
54-
* @return {void}
49+
* @inheritdoc
5550
*/
5651
reset() {
5752
this._value = null;
@@ -86,23 +81,10 @@ export class FilterInputModel extends Observable {
8681
}
8782

8883
/**
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
10385
*/
104-
valueFromRaw(raw) {
105-
return raw.trim();
86+
get normalized() {
87+
return this.value;
10688
}
10789

10890
/**

0 commit comments

Comments
 (0)