New answers tagged

2

Let's separate it by responsibilities into renderKids, renderName, traverseTree so that: the main function can start explicitly from where you want functions become immutable, free of side-effects less repeated code a single return is used hopefully, the intent and flow become more obvious function renderTree(json) { function renderKids(kids) { ...


2

Some suggestions: Since this is an async function, it seems likely the caller may want to know when it's done and if it succeeded. To do that, you need to reject upon error. That means rethrow after logging inside your catch. This allows the error to get back to the caller as a rejected promise. Simplify by changing config.archives.reduce() to config....


3

Tips for JS code optimization: Variable names Give your variables meaningful names: const r1 = await dialog.showOpenDialog(...) can be renamed to dirs or dirList (representing selected directories) const r2 = await fsp.readFile('./config.json', 'utf8'), config = JSON.parse(r2), where r2 is supposed to be a config file path. Let's rename it to say const ...


Top 50 recent answers are included