Apply a throttle to filter condition updates

This commit is contained in:
Travis Ralston 2020-07-26 15:01:18 -06:00
parent 517c93a7d5
commit a15aae4daf

View file

@ -18,6 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { FILTER_CHANGED, FilterPriority, IFilterCondition } from "./IFilterCondition"; import { FILTER_CHANGED, FilterPriority, IFilterCondition } from "./IFilterCondition";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { removeHiddenChars } from "matrix-js-sdk/src/utils"; import { removeHiddenChars } from "matrix-js-sdk/src/utils";
import { throttle } from "lodash";
/** /**
* A filter condition for the room list which reveals rooms of a particular * A filter condition for the room list which reveals rooms of a particular
@ -41,9 +42,13 @@ export class NameFilterCondition extends EventEmitter implements IFilterConditio
public set search(val: string) { public set search(val: string) {
this._search = val; this._search = val;
this.emit(FILTER_CHANGED); this.callUpdate();
} }
private callUpdate = throttle(() => {
this.emit(FILTER_CHANGED);
}, 200, {trailing: true, leading: true});
public isVisible(room: Room): boolean { public isVisible(room: Room): boolean {
const lcFilter = this.search.toLowerCase(); const lcFilter = this.search.toLowerCase();
if (this.search[0] === '#') { if (this.search[0] === '#') {