{"size": 798, "ext": "js", "max_stars_repo_path": "vendor/flarum/core/js/lib/initializers/preload.js", "max_stars_repo_name": "qiujiafei123/FlarumChinaBBS", "max_stars_repo_stars_event_min_datetime": "2018-04-16T01:40:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-16T01:40:31.000Z", "max_issues_repo_path": "vendor/flarum/core/js/lib/initializers/preload.js", "max_issues_repo_name": "qiujiafei123/FlarumChinaBBS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vendor/flarum/core/js/lib/initializers/preload.js", "max_forks_repo_name": "qiujiafei123/FlarumChinaBBS", "max_forks_repo_forks_event_min_datetime": "2019-10-23T22:14:30.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-23T22:14:30.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 31.92, "max_line_length": 79, "alphanum_fraction": 0.7155388471}
import Session from 'flarum/Session';

/**
 * 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 preload(app) {
  app.store.pushPayload({data: app.data.resources});

  app.forum = app.store.getById('forums', 1);

  app.session = new Session(
    app.store.getById('users', app.data.session.userId),
    app.data.session.csrfToken
  );
}
