Preload data just before boot, not when the store is initialised

This commit is contained in:
Toby Zerner
2015-07-22 09:54:49 +09:30
parent 49e9ab362a
commit 23cd3320c0
2 changed files with 11 additions and 10 deletions

View File

@ -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)