From a97144366d234bf1f5e6c7f92a48706d5eccf524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 15 Nov 2019 11:07:06 +0100 Subject: [PATCH] [FIX] playground: fix downloaded app code The generated downloaded code from the playground did not work because it did not load templates into QWeb anymore. closes #461 --- tools/playground/app.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/playground/app.js b/tools/playground/app.js index f4d841fc..3345f67a 100644 --- a/tools/playground/app.js +++ b/tools/playground/app.js @@ -120,20 +120,34 @@ async function makeApp(js, css, xml) { .join("\n"); const JS = ` -async function loadTemplates() { - try { - return owl.utils.loadFile('app.xml'); - } catch(e) { - console.error(\`This app requires a static server. If you have python installed, try 'python app.py'\`); - } -} - -function start([TEMPLATES]) { - // Application code +/** + * This is the javascript code defined in the playground. + * In a larger application, this code should probably be moved in different + * sub files. + */ +function app() { ${processedJS} } -Promise.all([loadTemplates(), owl.utils.whenReady()]).then(start); +/** + * Initialization code + * This code load templates, and make sure everything is properly connected. + */ +async function start() { + let templates; + try { + templates = await owl.utils.loadFile('app.xml'); + } catch(e) { + console.error(\`This app requires a static server. If you have python installed, try 'python app.py'\`); + return; + } + const env = { qweb: new owl.QWeb({templates})}; + owl.Component.env = env; + await owl.utils.whenReady(); + app(); +} + +start(); `; zip.file("app.js", JS);