From bd33ef5dc96a938fe1886cc6775d7e38652c055d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 10 Sep 2022 22:10:36 +0200 Subject: keep mic_gain in sync with prefs --- client-web/source/preferences/mod.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'client-web/source/preferences/mod.ts') diff --git a/client-web/source/preferences/mod.ts b/client-web/source/preferences/mod.ts index 5f238bb..d1f3635 100644 --- a/client-web/source/preferences/mod.ts +++ b/client-web/source/preferences/mod.ts @@ -17,14 +17,17 @@ type PrefMap = { [Key in keyof T type Optional = { [Key in keyof T]?: T[Key] } export const { prefs: PREFS, explicit: PREFS_EXPLICIT } = register_prefs(PREF_DECLS) const pref_change_handlers: Map unknown>> = new Map() -export const on_pref_changed = (key: keyof typeof PREFS, cb: () => unknown) => - (pref_change_handlers.get(key) +export const on_pref_changed = (key: keyof typeof PREFS, cb: () => unknown): (() => void) => { + const m = (pref_change_handlers.get(key) ?? (() => { const n = new Set<() => unknown>(); pref_change_handlers.set(key, n); return n })() - ).add(cb) + ) + m.add(cb) + return () => m.delete(cb) +} export function register_prefs>>(ds: T): { prefs: PrefMap, explicit: Optional> } { const prefs: PrefMap = {} as PrefMap -- cgit v1.2.3-70-g09d2