MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / applyConfig

Function applyConfig

frontend/src/ts/config/lifecycle.ts:70–111  ·  view source on GitHub ↗
(
  partialConfig: Partial<ConfigSchemas.Config>,
)

Source from the content-addressed store, hash-verified

68]);
69
70export async function applyConfig(
71 partialConfig: Partial<ConfigSchemas.Config>,
72): Promise<void> {
73 if (partialConfig === undefined || partialConfig === null) return;
74
75 //migrate old values if needed, remove additional keys and merge with default config
76 const fullConfig: ConfigSchemas.Config = migrateConfig(partialConfig);
77
78 configEvent.dispatch({ key: "fullConfigChange" });
79
80 const defaultConfig = getDefaultConfig();
81 for (const key of typedKeys(fullConfig)) {
82 //@ts-expect-error this is fine, both are of type config
83 Config[key] = defaultConfig[key];
84 }
85
86 const configKeysToReset: (keyof ConfigSchemas.Config)[] = [];
87
88 const firstKeys = typedKeys(fullConfig).filter(
89 (key) => !lastConfigsToApply.has(key),
90 );
91
92 for (const configKey of [...firstKeys, ...lastConfigsToApply]) {
93 const configValue = fullConfig[configKey];
94
95 const set = setConfig(configKey, configValue, {
96 nosave: true,
97 partOfFullConfigChange: true,
98 });
99
100 if (!set) {
101 configKeysToReset.push(configKey);
102 }
103 }
104
105 for (const key of configKeysToReset) {
106 saveToLocalStorage(key);
107 }
108
109 configEvent.dispatch({ key: "fullConfigChangeFinished" });
110 setFullConfigStore(fullConfig);
111}
112
113export async function resetConfig(): Promise<void> {
114 await applyConfig(getDefaultConfig());

Callers 5

applyFunction · 0.90
updateFromServerFunction · 0.90
applyConfigFromJsonFunction · 0.70
loadFromLocalStorageFunction · 0.70
resetConfigFunction · 0.70

Calls 8

migrateConfigFunction · 0.90
getDefaultConfigFunction · 0.90
typedKeysFunction · 0.90
setConfigFunction · 0.90
saveToLocalStorageFunction · 0.90
setFullConfigStoreFunction · 0.90
dispatchMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected