From 23cd3320c03de28340b8648f23f3430fd68e489b Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 22 Jul 2015 09:54:49 +0930 Subject: [PATCH] Preload data just before boot, not when the store is initialised --- js/lib/initializers/preload.js | 13 ++++++++++--- js/lib/initializers/store.js | 8 +------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/js/lib/initializers/preload.js b/js/lib/initializers/preload.js index f41e9704b..b170ac985 100644 --- a/js/lib/initializers/preload.js +++ b/js/lib/initializers/preload.js @@ -1,15 +1,22 @@ import Session from 'flarum/Session'; /** - * The `session` initializer creates the application session and preloads it - * with data that has been set on the application's `preload` property. + * The `preload` initializer creates the application session and preloads it + * with data that has been set on the application's `preload` property. It also + * preloads any data on the application's `preload` property into the store. + * Finally, it sets the application's `forum` instance to the one that was + * preloaded. * * `app.preload.session` should be the same as the response from the /api/token * endpoint: it should contain `token` and `userId` keys. * * @param {App} app */ -export default function session(app) { +export default function preload(app) { + app.store.pushPayload({data: app.preload.data}); + + app.forum = app.store.getById('forums', 1); + app.session = new Session( app.preload.session.token, app.store.getById('users', app.preload.session.userId) diff --git a/js/lib/initializers/store.js b/js/lib/initializers/store.js index a55f65664..e4bfa19dd 100644 --- a/js/lib/initializers/store.js +++ b/js/lib/initializers/store.js @@ -9,9 +9,7 @@ import Notification from 'flarum/models/Notification'; /** * The `store` initializer creates the application's data store and registers - * the default resource types to their models. It then preloads any data on the - * application's `preload` property into the store. Finally, it sets the - * application's `forum` instance to the one that was preloaded. + * the default resource types to their models. * * @param {App} app */ @@ -25,8 +23,4 @@ export default function store(app) { activity: Activity, notifications: Notification }); - - app.store.pushPayload({data: app.preload.data}); - - app.forum = app.store.getById('forums', 1); }