Basic debounce for value field
This commit is contained in:
parent
000a40aa82
commit
eff73d6afe
@ -1,4 +1,4 @@
|
|||||||
import { Subject } from 'rxjs'
|
import { debounceTime, distinctUntilChanged, Subject } from 'rxjs'
|
||||||
import { CustomFieldDataType } from './custom-field'
|
import { CustomFieldDataType } from './custom-field'
|
||||||
|
|
||||||
export enum CustomFieldQueryLogicalOperator {
|
export enum CustomFieldQueryLogicalOperator {
|
||||||
@ -112,10 +112,20 @@ export enum CustomFieldQueryElementType {
|
|||||||
export class CustomFieldQueryElement {
|
export class CustomFieldQueryElement {
|
||||||
public readonly type: CustomFieldQueryElementType
|
public readonly type: CustomFieldQueryElementType
|
||||||
public changed: Subject<CustomFieldQueryElement>
|
public changed: Subject<CustomFieldQueryElement>
|
||||||
|
protected valueModelChanged: Subject<string | CustomFieldQueryElement[]>
|
||||||
|
|
||||||
constructor(type: CustomFieldQueryElementType) {
|
constructor(type: CustomFieldQueryElementType) {
|
||||||
this.type = type
|
this.type = type
|
||||||
this.changed = new Subject<CustomFieldQueryElement>()
|
this.changed = new Subject<CustomFieldQueryElement>()
|
||||||
|
this.valueModelChanged = new Subject<string | CustomFieldQueryElement[]>()
|
||||||
|
this.connectValueModelChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected connectValueModelChanged() {
|
||||||
|
// Allows overriding in subclasses
|
||||||
|
this.valueModelChanged.subscribe(() => {
|
||||||
|
this.changed.next(this)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public serialize() {
|
public serialize() {
|
||||||
@ -135,17 +145,12 @@ export class CustomFieldQueryElement {
|
|||||||
return this._operator
|
return this._operator
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _value:
|
protected _value: string | CustomFieldQueryElement[] = null
|
||||||
| string
|
set value(value: string | CustomFieldQueryElement[]) {
|
||||||
| CustomFieldQueryAtom[]
|
|
||||||
| CustomFieldQueryExpression[] = null
|
|
||||||
set value(
|
|
||||||
value: string | CustomFieldQueryAtom[] | CustomFieldQueryExpression[]
|
|
||||||
) {
|
|
||||||
this._value = value
|
this._value = value
|
||||||
this.changed.next(this)
|
this.valueModelChanged.next(value)
|
||||||
}
|
}
|
||||||
get value(): string | CustomFieldQueryAtom[] | CustomFieldQueryExpression[] {
|
get value(): string | CustomFieldQueryElement[] {
|
||||||
return this._value
|
return this._value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,6 +170,14 @@ export class CustomFieldQueryAtom extends CustomFieldQueryElement {
|
|||||||
;[this._field, this._operator, this._value] = queryArray
|
;[this._field, this._operator, this._value] = queryArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected connectValueModelChanged(): void {
|
||||||
|
this.valueModelChanged
|
||||||
|
.pipe(debounceTime(1000), distinctUntilChanged())
|
||||||
|
.subscribe(() => {
|
||||||
|
this.changed.next(this)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public serialize() {
|
public serialize() {
|
||||||
return [this._field, this._operator, this._value.toString()]
|
return [this._field, this._operator, this._value.toString()]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user