From c916ef453490b718854989ca2a74ac476b61934a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 6 Feb 2020 17:57:17 +0000 Subject: [PATCH] Only emit in RoomViewStore when state actually changes This adds a shallow state check to attempt to only emit a store update when something actually changes. Fixes https://github.com/vector-im/riot-web/issues/12256 --- src/stores/RoomViewStore.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index 9bcc2815e6..64dfd56b2f 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -66,6 +66,20 @@ class RoomViewStore extends Store { } _setState(newState) { + // If values haven't changed, there's nothing to do. + // This only tries a shallow comparison, so unchanged objects will slip + // through, but that's probably okay for now. + let stateChanged = false; + for (const key of Object.keys(newState)) { + if (this._state[key] !== newState[key]) { + stateChanged = true; + break; + } + } + if (!stateChanged) { + return; + } + this._state = Object.assign(this._state, newState); this.__emitChange(); }