From 4ad101dca16a993bf9fe4cc0065e9312e3bf18e0 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 1 May 2019 18:20:14 +0300 Subject: [PATCH] feature(config) speed up load: series -> parallel --- client/modules/config.js | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/client/modules/config.js b/client/modules/config.js index d5cd86e1..4579b198 100644 --- a/client/modules/config.js +++ b/client/modules/config.js @@ -5,7 +5,6 @@ require('../../css/config.css'); const rendy = require('rendy/legacy'); -const exec = require('execon'); const currify = require('currify/legacy'); const wraptile = require('wraptile/legacy'); const squad = require('squad/legacy'); @@ -43,7 +42,10 @@ const addChange = currify((fn, input) => { const Config = {}; -let Loading = true; +let Template; + +const getFile = promisify(Files.get); +const loadCSS = promisify(load.css); module.exports.init = async () => { if (!CloudCmd.config('configDialog')) @@ -51,10 +53,16 @@ module.exports.init = async () => { showLoad(); - await CloudCmd.View(); - await loadSocket(); + const {prefix} = CloudCmd; + + [Template] = await Promise.all([ + getFile('config-tmpl'), + loadSocket(), + loadCSS(prefix + '/dist/config.css'), + CloudCmd.View(), + ]); + initSocket(); - Loading = false; }; const { @@ -63,7 +71,6 @@ const { } = CloudCmd; let Element; -let Template; function getHost() { const { @@ -125,23 +132,10 @@ function show() { if (!CloudCmd.config('configDialog')) return; - const {prefix} = CloudCmd; - const funcs = [ - exec.with(Files.get, 'config-tmpl'), - exec.with(load.css, prefix + '/dist/config.css'), - ]; - - if (Loading) - return; - - showLoad(); - exec.parallel(funcs, fillTemplate); + fillTemplate(); } -function fillTemplate(error, template) { - if (!Template) - Template = template; - +function fillTemplate() { Files.get('config', (error, config) => { if (error) return alert('Could not load config!');