MCPcopy
hub / github.com/monkeytypegame/monkeytype / setConfig

Function setConfig

frontend/src/ts/config/setters.ts:18–147  ·  view source on GitHub ↗
(
  key: T,
  value: ConfigSchemas.Config[T],
  options?: {
    nosave?: boolean;
    partOfFullConfigChange?: boolean;
  },
)

Source from the content-addressed store, hash-verified

16import { FunboxName } from "@monkeytype/schemas/configs";
17
18export function setConfig<T extends keyof ConfigSchemas.Config>(
19 key: T,
20 value: ConfigSchemas.Config[T],
21 options?: {
22 nosave?: boolean;
23 partOfFullConfigChange?: boolean;
24 },
25): boolean {
26 const metadata = configMetadata[key] as ConfigMetadataObject[T];
27 if (metadata === undefined) {
28 throw new Error(`Config metadata for key "${key}" is not defined.`);
29 }
30
31 if (metadata.overrideValue) {
32 value = metadata.overrideValue({
33 value,
34 currentValue: Config[key],
35 currentConfig: Config,
36 });
37 }
38
39 const previousValue = Config[key];
40
41 if (
42 metadata.changeRequiresRestart &&
43 TestState.isActive &&
44 Config.funbox.includes("no_quit")
45 ) {
46 showNoticeNotification(
47 "No quit funbox is active. Please finish the test.",
48 {
49 important: true,
50 },
51 );
52 console.warn(
53 `Could not set config key "${key}" with value "${JSON.stringify(
54 value,
55 )}" - no quit funbox active.`,
56 );
57 return false;
58 }
59
60 if (metadata.isBlocked?.({ value, currentConfig: Config })) {
61 console.warn(
62 `Could not set config key "${key}" with value "${JSON.stringify(
63 value,
64 )}" - blocked.`,
65 );
66 return false;
67 }
68
69 const schema = ConfigSchemas.ConfigSchema.shape[key] as ZodSchema;
70
71 if (!isConfigValueValid(metadata.displayString ?? key, value, schema)) {
72 console.warn(
73 `Could not set config key "${key}" with value "${JSON.stringify(
74 value,
75 )}" - invalid value.`,

Callers 15

loadCustomThemeFromUrlFunction · 0.90
loadTestSettingsFromUrlFunction · 0.90
setupFunction · 0.90
setFunction · 0.90
randomizeThemeFunction · 0.90
handleClickFunction · 0.90
handleModeClickFunction · 0.90
handleTimeClickFunction · 0.90
handleWordsClickFunction · 0.90
handleQuoteLengthClickFunction · 0.90
MobileTestConfigModalFunction · 0.90
applyQuoteFunction · 0.90

Calls 9

showNoticeNotificationFunction · 0.90
isConfigValueValidFunction · 0.90
camelCaseToWordsFunction · 0.90
typedKeysFunction · 0.90
saveToLocalStorageFunction · 0.90
setConfigStoreFunction · 0.90
triggerResizeFunction · 0.90
dispatchMethod · 0.80

Tested by

no test coverage detected