Use a global WatchManager for settings

Fixes https://github.com/vector-im/riot-web/issues/8936

Watchers are now managed by the SettingsStore itself through a global/default watch manager. As per the included documentation, the watch manager dispatches updates to callbacks which are redirected by the SettingsStore for consumer safety.
This commit is contained in:
Travis Ralston 2019-02-26 12:43:10 -07:00
parent 426bdafe22
commit 93673eff12
13 changed files with 111 additions and 174 deletions

View file

@ -41,7 +41,11 @@ export class WatchManager {
}
}
notifyUpdate(settingName, inRoomId, newValue) {
notifyUpdate(settingName, inRoomId, atLevel, newValueAtLevel) {
// Dev note: We could avoid raising changes for ultimately inconsequential changes, but
// we also don't have a reliable way to get the old value of a setting. Instead, we'll just
// let it fall through regardless and let the receiver dedupe if they want to.
if (!this._watchers[settingName]) return;
const roomWatchers = this._watchers[settingName];
@ -51,7 +55,7 @@ export class WatchManager {
if (roomWatchers[null]) callbacks.push(...roomWatchers[null]);
for (const callback of callbacks) {
callback(inRoomId, newValue);
callback(inRoomId, atLevel, newValueAtLevel);
}
}
}