@samitouri / QOSami-HFS / commits / a6a10c58

better code

Massimo Melina committed May 4, 2023 at 23:17 UTC a6a10c58638ff80775e605f698b62d45c80d44c1
2 files changed +2 -4
src/config.ts
+1 -1
@@ -43,7 +43,7 @@ if (!existsSync(path) && existsSync(legacyPosition))
43 }
44 catch {}
45 }
46 -const { save } = watchLoad(path, values => setConfig(values||{}, false), {
46 +const { save } = watchLoad(path, text => setConfig(yaml.parse(text)||{}, false), {
47 failedOnFirstAttempt(){
48 console.log("No config file, using defaults")
49 setConfig({}, false)
src/watchLoad.ts
+1 -3
@@ -2,7 +2,6 @@
2
3 import { FSWatcher, watch } from 'fs'
4 import fs from 'fs/promises'
5 -import yaml from 'yaml'
5 import { debounceAsync, readFileBusy } from './misc'
6
7 export type WatchLoadCanceller = () => void
@@ -65,8 +64,7 @@ export function watchLoad(path:string, parser:(data:any)=>void|Promise<void>, {
64 last = text
65 console.debug('loaded', path)
66 uninstall(); install() // reinstall, as the original file could have been renamed. We watch by the name.
68 - const decoded = path.endsWith('.yaml') ? yaml.parse(text) : text
69 - await parser(decoded)
67 + await parser(text)
68 }
69 finally {
70 doing = false