From 5e7f518fed661961d2fd8040659214f52ffa6b4d Mon Sep 17 00:00:00 2001 From: Harald Roelle Date: Sun, 20 Feb 2022 12:54:59 +0100 Subject: [PATCH 1/3] Fix race condition --- www/ftui/components/element.component.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/www/ftui/components/element.component.js b/www/ftui/components/element.component.js index 5c18edb1..53c41942 100755 --- a/www/ftui/components/element.component.js +++ b/www/ftui/components/element.component.js @@ -9,6 +9,7 @@ import * as ftuiHelper from '../modules/ftui/ftui.helper.js'; +let ftuiAppMod = await import( '../modules/ftui/ftui.app.js'); const uids = {}; @@ -32,9 +33,7 @@ export class FtuiElement extends HTMLElement { this.createShadowRoot(this.template()); } - if (window.ftuiApp) { - ftuiApp.attachBinding(this); - } + ftuiAppMod.ftuiApp.attachBinding(this); } createShadowRoot(content) { From 4a84871be7e03e81ec14ab5ffcb21b1099f8dabb Mon Sep 17 00:00:00 2001 From: Harald Roelle Date: Sun, 27 Feb 2022 10:57:39 +0100 Subject: [PATCH 2/3] Variant that avoids dependency on FtuiApp --- www/ftui/components/element.component.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/www/ftui/components/element.component.js b/www/ftui/components/element.component.js index 53c41942..29b2bc84 100755 --- a/www/ftui/components/element.component.js +++ b/www/ftui/components/element.component.js @@ -9,7 +9,6 @@ import * as ftuiHelper from '../modules/ftui/ftui.helper.js'; -let ftuiAppMod = await import( '../modules/ftui/ftui.app.js'); const uids = {}; @@ -33,7 +32,11 @@ export class FtuiElement extends HTMLElement { this.createShadowRoot(this.template()); } - ftuiAppMod.ftuiApp.attachBinding(this); + // solution adapted from the very useful thread https://stackoverflow.com/questions/7307983/while-variable-is-not-defined-wait + (async () => { + while (typeof window.ftuiApp === 'undefined') await new Promise(resolve => setTimeout(resolve, 2000)); + window.ftuiApp.attachBinding(this); + })(); } createShadowRoot(content) { From 458878ed631584ffebc7e342c24a9ab7ef1c6a28 Mon Sep 17 00:00:00 2001 From: Harald Roelle Date: Sun, 27 Feb 2022 12:31:47 +0100 Subject: [PATCH 3/3] Make solution more robust --- www/ftui/components/element.component.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/ftui/components/element.component.js b/www/ftui/components/element.component.js index 29b2bc84..7890f751 100755 --- a/www/ftui/components/element.component.js +++ b/www/ftui/components/element.component.js @@ -35,7 +35,8 @@ export class FtuiElement extends HTMLElement { // solution adapted from the very useful thread https://stackoverflow.com/questions/7307983/while-variable-is-not-defined-wait (async () => { while (typeof window.ftuiApp === 'undefined') await new Promise(resolve => setTimeout(resolve, 2000)); - window.ftuiApp.attachBinding(this); + if (typeof window.ftuiApp === 'object') + window.ftuiApp.attachBinding(this); })(); }