From bae31831fe79805be146cf6d0754a791da60aec7 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 20 Jun 2016 15:11:28 +0100 Subject: [PATCH] subscriptions: load on DOM ready --- index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 6c6a0f2..42028cb 100644 --- a/index.js +++ b/index.js @@ -81,14 +81,17 @@ function choo () { // subscriptions are loaded after sendAction() is called // because they both need access to send() and can't - // react to actions (read-only) - _models.forEach(function (model) { - if (model.subscriptions) { - assert.ok(Array.isArray(model.subscriptions), 'subs must be an array') - model.subscriptions.forEach(function (sub) { - sub(send) - }) - } + // react to actions (read-only) - also wait on DOM to + // be loaded + document.addEventListener('DOMContentLoaded', function () { + _models.forEach(function (model) { + if (model.subscriptions) { + assert.ok(Array.isArray(model.subscriptions), 'subs must be an arr') + model.subscriptions.forEach(function (sub) { + sub(send) + }) + } + }) }) // If an id is provided, the application will rehydrate