Skip to content

Commit 2835a02

Browse files
committed
impr: add type safety to the config event observable
!nuf
1 parent 4d570d3 commit 2835a02

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

frontend/src/ts/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ export function setCustomLayoutfluid(
19011901
const customLayoutfluid = trimmed.replace(/ /g, "#");
19021902
config.customLayoutfluid = customLayoutfluid;
19031903
saveToLocalStorage("customLayoutfluid", nosave);
1904-
ConfigEvent.dispatch("customLayoutFluid", config.customLayoutfluid);
1904+
ConfigEvent.dispatch("customLayoutfluid", config.customLayoutfluid);
19051905

19061906
return true;
19071907
}

frontend/src/ts/elements/modes-notice.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@ import Format from "../utils/format";
1212
import { getActiveFunboxNames } from "../test/funbox/list";
1313

1414
ConfigEvent.subscribe((eventKey) => {
15-
if (
16-
[
17-
"difficulty",
18-
"blindMode",
19-
"stopOnError",
20-
"paceCaret",
21-
"minWpm",
22-
"minAcc",
23-
"minBurst",
24-
"confidenceMode",
25-
"layout",
26-
"showAverage",
27-
"typingSpeedUnit",
28-
"quickRestart",
29-
"changeCustomPolyglot",
30-
].includes(eventKey)
31-
) {
15+
const configKeys: ConfigEvent.ConfigEventKey[] = [
16+
"difficulty",
17+
"blindMode",
18+
"stopOnError",
19+
"paceCaret",
20+
"minWpm",
21+
"minAcc",
22+
"minBurst",
23+
"confidenceMode",
24+
"layout",
25+
"showAverage",
26+
"typingSpeedUnit",
27+
"quickRestart",
28+
"customPolyglot",
29+
];
30+
if (configKeys.includes(eventKey)) {
3231
void update();
3332
}
3433
});

frontend/src/ts/elements/settings/theme-picker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ $(".pageSettings #saveCustomThemeButton").on("click", async () => {
479479
});
480480

481481
ConfigEvent.subscribe((eventKey) => {
482-
if (eventKey === "customThemeId") void refreshButtons();
483482
if (eventKey === "theme" && ActivePage.get() === "settings") {
484483
updateActiveButton();
485484
}

frontend/src/ts/observables/config-event.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import { Config, ConfigValue } from "@monkeytype/contracts/schemas/configs";
1+
import {
2+
Config,
3+
ConfigKey,
4+
ConfigValue,
5+
} from "@monkeytype/contracts/schemas/configs";
6+
7+
export type ConfigEventKey =
8+
| ConfigKey
9+
| "saveToLocalStorage"
10+
| "setThemes"
11+
| "configApplied"
12+
| "fullConfigChange"
13+
| "fullConfigChangeFinished";
214

315
type SubscribeFunction = (
4-
key: string,
16+
key: ConfigEventKey,
517
newValue?: ConfigValue,
618
nosave?: boolean,
719
previousValue?: ConfigValue,
@@ -15,7 +27,7 @@ export function subscribe(fn: SubscribeFunction): void {
1527
}
1628

1729
export function dispatch(
18-
key: string,
30+
key: ConfigEventKey,
1931
newValue?: ConfigValue,
2032
nosave?: boolean,
2133
previousValue?: ConfigValue,

frontend/src/ts/test/test-logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
14321432
}
14331433
if (eventKey === "difficulty" && !nosave) restart();
14341434
if (
1435-
eventKey === "customLayoutFluid" &&
1435+
eventKey === "customLayoutfluid" &&
14361436
Config.funbox.includes("layoutfluid")
14371437
) {
14381438
restart();

0 commit comments

Comments
 (0)