mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-29 03:20:46 +08:00
impr: add type safety to the config event observable
!nuf
This commit is contained in:
parent
4d570d32b0
commit
2835a02bbb
5 changed files with 33 additions and 23 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -479,7 +479,6 @@ $(".pageSettings #saveCustomThemeButton").on("click", async () => {
|
|||
});
|
||||
|
||||
ConfigEvent.subscribe((eventKey) => {
|
||||
if (eventKey === "customThemeId") void refreshButtons();
|
||||
if (eventKey === "theme" && ActivePage.get() === "settings") {
|
||||
updateActiveButton();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1432,7 +1432,7 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
|
|||
}
|
||||
if (eventKey === "difficulty" && !nosave) restart();
|
||||
if (
|
||||
eventKey === "customLayoutFluid" &&
|
||||
eventKey === "customLayoutfluid" &&
|
||||
Config.funbox.includes("layoutfluid")
|
||||
) {
|
||||
restart();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue