impr: add type safety to the config event observable

!nuf
This commit is contained in:
Miodec 2025-04-18 20:31:48 +02:00
parent 4d570d32b0
commit 2835a02bbb
5 changed files with 33 additions and 23 deletions

View file

@ -1901,7 +1901,7 @@ export function setCustomLayoutfluid(
const customLayoutfluid = trimmed.replace(/ /g, "#");
config.customLayoutfluid = customLayoutfluid;
saveToLocalStorage("customLayoutfluid", nosave);
ConfigEvent.dispatch("customLayoutFluid", config.customLayoutfluid);
ConfigEvent.dispatch("customLayoutfluid", config.customLayoutfluid);
return true;
}

View file

@ -12,23 +12,22 @@ import Format from "../utils/format";
import { getActiveFunboxNames } from "../test/funbox/list";
ConfigEvent.subscribe((eventKey) => {
if (
[
"difficulty",
"blindMode",
"stopOnError",
"paceCaret",
"minWpm",
"minAcc",
"minBurst",
"confidenceMode",
"layout",
"showAverage",
"typingSpeedUnit",
"quickRestart",
"changeCustomPolyglot",
].includes(eventKey)
) {
const configKeys: ConfigEvent.ConfigEventKey[] = [
"difficulty",
"blindMode",
"stopOnError",
"paceCaret",
"minWpm",
"minAcc",
"minBurst",
"confidenceMode",
"layout",
"showAverage",
"typingSpeedUnit",
"quickRestart",
"customPolyglot",
];
if (configKeys.includes(eventKey)) {
void update();
}
});

View file

@ -479,7 +479,6 @@ $(".pageSettings #saveCustomThemeButton").on("click", async () => {
});
ConfigEvent.subscribe((eventKey) => {
if (eventKey === "customThemeId") void refreshButtons();
if (eventKey === "theme" && ActivePage.get() === "settings") {
updateActiveButton();
}

View file

@ -1,7 +1,19 @@
import { Config, ConfigValue } from "@monkeytype/contracts/schemas/configs";
import {
Config,
ConfigKey,
ConfigValue,
} from "@monkeytype/contracts/schemas/configs";
export type ConfigEventKey =
| ConfigKey
| "saveToLocalStorage"
| "setThemes"
| "configApplied"
| "fullConfigChange"
| "fullConfigChangeFinished";
type SubscribeFunction = (
key: string,
key: ConfigEventKey,
newValue?: ConfigValue,
nosave?: boolean,
previousValue?: ConfigValue,
@ -15,7 +27,7 @@ export function subscribe(fn: SubscribeFunction): void {
}
export function dispatch(
key: string,
key: ConfigEventKey,
newValue?: ConfigValue,
nosave?: boolean,
previousValue?: ConfigValue,

View file

@ -1432,7 +1432,7 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
}
if (eventKey === "difficulty" && !nosave) restart();
if (
eventKey === "customLayoutFluid" &&
eventKey === "customLayoutfluid" &&
Config.funbox.includes("layoutfluid")
) {
restart();