subscriptions: load on DOM ready

This commit is contained in:
Yoshua Wuyts
2016-06-20 15:11:28 +01:00
parent b6eb994357
commit bae31831fe
+11 -8
View File
@@ -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