Ensure CustomRoomTagStore doesn't fire useless updates
This could in theory cause double rendering of the room list under some conditions.pull/21833/head
parent
5f034ee4ed
commit
b91026fa89
|
@ -22,6 +22,7 @@ import SettingsStore from "../settings/SettingsStore";
|
|||
import RoomListStore, {LISTS_UPDATE_EVENT} from "./room-list/RoomListStore";
|
||||
import {RoomNotificationStateStore} from "./notifications/RoomNotificationStateStore";
|
||||
import {isCustomTag} from "./room-list/models";
|
||||
import {objectHasDiff} from "../utils/objects";
|
||||
|
||||
function commonPrefix(a, b) {
|
||||
const len = Math.min(a.length, b.length);
|
||||
|
@ -107,7 +108,10 @@ class CustomRoomTagStore extends EventEmitter {
|
|||
}
|
||||
|
||||
_onListsUpdated = () => {
|
||||
this._setState({tags: this._getUpdatedTags()});
|
||||
const newTags = this._getUpdatedTags();
|
||||
if (!this._state.tags || objectHasDiff(this._state.tags, newTags)) {
|
||||
this._setState({tags: newTags});
|
||||
}
|
||||
};
|
||||
|
||||
_onDispatch(payload) {
|
||||
|
@ -134,7 +138,7 @@ class CustomRoomTagStore extends EventEmitter {
|
|||
|
||||
_getUpdatedTags() {
|
||||
if (!SettingsStore.isFeatureEnabled("feature_custom_tags")) {
|
||||
return;
|
||||
return {}; // none
|
||||
}
|
||||
|
||||
const newTagNames = Object.keys(RoomListStore.instance.orderedLists).filter(t => isCustomTag(t)).sort();
|
||||
|
|
|
@ -72,6 +72,23 @@ export function objectHasValueChange(a: any, b: any): boolean {
|
|||
return arrayHasDiff(aValues, bValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if any keys were added, removed, or changed between two objects.
|
||||
* For changes, simple triple equal comparisons are done, not in-depth
|
||||
* tree checking.
|
||||
* @param a The first object. Must be defined.
|
||||
* @param b The second object. Must be defined.
|
||||
* @returns True if there's a difference between the objects, false otherwise
|
||||
*/
|
||||
export function objectHasDiff(a: any, b: any): boolean {
|
||||
const aKeys = Object.keys(a);
|
||||
const bKeys = Object.keys(b);
|
||||
if (arrayHasDiff(aKeys, bKeys)) return true;
|
||||
|
||||
const possibleChanges = arrayUnion(aKeys, bKeys);
|
||||
return possibleChanges.some(k => a[k] !== b[k]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the keys added, changed, and removed between two objects.
|
||||
* For changes, simple triple equal comparisons are done, not in-depth
|
||||
|
|
Loading…
Reference in New Issue