fix: removing a key from config.yaml didn't reset corresponding state

Massimo Melina committed Mar 4, 2022 at 10:28 UTC 54c6010488ed4c42e42afc6a8988f08e5045322b
1 file changed +8 -2
src/config.ts
+8 -2
@@ -71,7 +71,7 @@ export function getWholeConfig({ omit=[], only=[] }: { omit:string[], only:strin
71 return _.cloneDeep(copy)
72 }
73
74 -// pass a value to `save` to force saving decision, or leave undefined for auto
74 +// pass a value to `save` to force saving decision, or leave undefined for auto. Passing false will also reset previously loaded configs.
75 export function setConfig(newCfg: Record<string,any>, save?: boolean) {
76 for (const k in newCfg)
77 check(k)
@@ -79,7 +79,13 @@ export function setConfig(newCfg: Record<string,any>, save?: boolean) {
79 saveConfigAsap().then()
80 return
81 }
82 - if (started) return
82 + if (started) {
83 + if (save === false) // false is used when loading whole config, and in such case we should not leave previous values untreated. Also, we need this only after we already `started`.
84 + for (const k of Object.keys(state))
85 + if (!newCfg.hasOwnProperty(k))
86 + check(k)
87 + return
88 + }
89 // first time we emit also for the default values
90 for (const k of Object.keys(configProps))
91 if (!newCfg.hasOwnProperty(k))