From 2ab9a24a79980faed086c366070f3481c43e6573 Mon Sep 17 00:00:00 2001 From: Ludwig Schubert Date: Wed, 8 Nov 2017 10:16:10 -0800 Subject: [PATCH] explicitly trigger controller load event --- src/components.js | 3 +++ src/controller.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components.js b/src/components.js index 99e2453..7562138 100644 --- a/src/components.js +++ b/src/components.js @@ -86,6 +86,9 @@ const distillMain = function() { console.info('Runlevel 3: We can now listen to controller events.'); console.info('Runlevel 3->4.'); window.distillRunlevel += 1; + // If template was added after DOMContentLoaded we may have missed that event. + // Controller will check for that case, so trigger the event explicitly: + Controller.listeners.DOMContentLoaded(); console.info('Runlevel 4: Distill Template initialisation complete.'); }; diff --git a/src/controller.js b/src/controller.js index 3a8d482..c8e88a4 100644 --- a/src/controller.js +++ b/src/controller.js @@ -145,7 +145,11 @@ export const Controller = { }, DOMContentLoaded() { - if (Controller.loaded || !domContentLoaded()) { + if (Controller.loaded) { + console.warn('Controller received DOMContentLoaded but was already loaded!'); + return; + } else if (!domContentLoaded()) { + console.warn('Controller received DOMContentLoaded before appropriate document.readyState!'); return; } else { Controller.loaded = true;