Skip to content

Commit eea529a

Browse files
committed
ENG-1478: extract emitter key constants, fix stale TODO
1 parent 686fd05 commit eea529a

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

apps/roam/src/components/LeftSidebarView.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTit
2222
import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar";
2323
import extractRef from "roamjs-components/util/extractRef";
2424
import { getFormattedConfigTree, notify } from "~/utils/discourseConfigRef";
25-
import { onSettingChange } from "~/components/settings/utils/settingsEmitter";
25+
import {
26+
onSettingChange,
27+
settingKeys,
28+
} from "~/components/settings/utils/settingsEmitter";
2629
import {
2730
type LeftSidebarConfig,
2831
type LeftSidebarPersonalSectionConfig,
@@ -343,9 +346,12 @@ export const useConfig = () => {
343346
refreshConfigTree();
344347
setConfig(buildConfig());
345348
};
346-
const unsubGlobal = onSettingChange("global:Left sidebar", handleUpdate);
349+
const unsubGlobal = onSettingChange(
350+
settingKeys.globalLeftSidebar,
351+
handleUpdate,
352+
);
347353
const unsubPersonal = onSettingChange(
348-
"personal:Left sidebar",
354+
settingKeys.personalLeftSidebar,
349355
handleUpdate,
350356
);
351357
return () => {
@@ -356,9 +362,9 @@ export const useConfig = () => {
356362
return { config, setConfig };
357363
};
358364

359-
// TODO(ENG-1471): refreshAndNotify still needed for other subscribe() consumers
360-
// (PanelManager, Canvas). Left sidebar reactivity now uses emitter, but other
361-
// components still depend on notify(). Remove when all consumers migrate to emitter.
365+
// TODO(ENG-1471): refreshAndNotify still needed by settings panels
366+
// (LeftSidebarGlobalSettings, LeftSidebarPersonalSettings) for old-system CRUD.
367+
// Remove when settings panels also read via accessors + emitter.
362368
export const refreshAndNotify = () => {
363369
refreshConfigTree();
364370
notify();

apps/roam/src/components/settings/utils/pullWatchers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
type PersonalSettings,
1313
type DiscourseNodeSettings,
1414
} from "./zodSchema";
15-
import { emitSettingChange } from "./settingsEmitter";
15+
import { emitSettingChange, settingKeys } from "./settingsEmitter";
1616

1717
type PullWatchCallback = Parameters<AddPullWatch>[2];
1818

@@ -93,7 +93,7 @@ export const featureFlagHandlers: Partial<
9393
> = {
9494
/* eslint-disable @typescript-eslint/naming-convention */
9595
"Enable left sidebar": (newValue, oldValue) => {
96-
emitSettingChange("Enable left sidebar", newValue, oldValue);
96+
emitSettingChange(settingKeys.leftSidebarFlag, newValue, oldValue);
9797
},
9898
/* eslint-enable @typescript-eslint/naming-convention */
9999
};
@@ -109,7 +109,7 @@ type GlobalSettingsHandlers = {
109109
export const globalSettingsHandlers: GlobalSettingsHandlers = {
110110
/* eslint-disable @typescript-eslint/naming-convention */
111111
"Left sidebar": (newValue, oldValue) => {
112-
emitSettingChange("global:Left sidebar", newValue, oldValue);
112+
emitSettingChange(settingKeys.globalLeftSidebar, newValue, oldValue);
113113
},
114114
/* eslint-enable @typescript-eslint/naming-convention */
115115
};
@@ -125,7 +125,7 @@ type PersonalSettingsHandlers = {
125125
export const personalSettingsHandlers: PersonalSettingsHandlers = {
126126
/* eslint-disable @typescript-eslint/naming-convention */
127127
"Left sidebar": (newValue, oldValue) => {
128-
emitSettingChange("personal:Left sidebar", newValue, oldValue);
128+
emitSettingChange(settingKeys.personalLeftSidebar, newValue, oldValue);
129129
},
130130
/* eslint-enable @typescript-eslint/naming-convention */
131131
};

apps/roam/src/components/settings/utils/settingsEmitter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
type SettingChangeCallback = (newValue: unknown, oldValue: unknown) => void;
22

3+
export const settingKeys = {
4+
leftSidebarFlag: "Enable left sidebar",
5+
globalLeftSidebar: "global:Left sidebar",
6+
personalLeftSidebar: "personal:Left sidebar",
7+
} as const;
8+
39
const listeners = new Map<string, Set<SettingChangeCallback>>();
410

511
export const onSettingChange = (

apps/roam/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import {
3939
getPersonalSetting,
4040
} from "./components/settings/utils/accessors";
4141
import { setupPullWatchOnSettingsPage } from "./components/settings/utils/pullWatchers";
42-
import { onSettingChange } from "./components/settings/utils/settingsEmitter";
42+
import {
43+
onSettingChange,
44+
settingKeys,
45+
} from "./components/settings/utils/settingsEmitter";
4346
import { mountLeftSidebar } from "./components/LeftSidebarView";
4447

4548
export const DEFAULT_CANVAS_PAGE_FORMAT = "Canvas/*";
@@ -154,7 +157,7 @@ export default runExtension(async (onloadArgs) => {
154157
}
155158

156159
const unsubLeftSidebarFlag = onSettingChange(
157-
"Enable left sidebar",
160+
settingKeys.leftSidebarFlag,
158161
(newValue) => {
159162
const enabled = Boolean(newValue);
160163
const wrapper = document.querySelector<HTMLDivElement>(

0 commit comments

Comments
 (0)