Refactor the web app bootstrapping code

- All custom JS variables are now preloaded into the `app.data` object, rather than directly on the `app` object. This means that admin settings are available in `app.data.settings` rather than `app.settings`, etc.
- Cleaner route handler generation
- Renamed ConfigureClientView to ConfigureWebApp, though the former still exists and is deprecated
- Partial fix for #881 (strips ?nojs=1 from URL if possible, so that refreshing will attempt to load JS version again)
This commit is contained in:
Toby Zerner
2016-05-26 19:04:24 +09:30
parent 2525e3e7ad
commit 9bfb797fdc
49 changed files with 1575 additions and 1254 deletions

View File

@ -40,24 +40,6 @@ export default class App {
*/
this.routes = {};
/**
* An object containing data to preload into the application.
*
* @type {Object}
* @property {Object} preload.data An array of resource objects to preload
* into the data store.
* @property {Object} preload.document An API response document to be used
* by the route that is first activated.
* @property {Object} preload.session A response from the /api/token
* endpoint containing the session's authentication token and user ID.
* @public
*/
this.preload = {
data: null,
document: null,
session: null
};
/**
* An ordered list of initializers to bootstrap the application.
*
@ -125,8 +107,10 @@ export default class App {
*
* @public
*/
boot() {
this.translator.locale = this.locale;
boot(data) {
this.data = data;
this.translator.locale = data.locale;
this.initializers.toArray().forEach(initializer => initializer(this));
}
@ -138,9 +122,9 @@ export default class App {
* @public
*/
preloadedDocument() {
if (app.preload.document) {
const results = app.store.pushPayload(app.preload.document);
app.preload.document = null;
if (this.data.document) {
const results = this.store.pushPayload(this.data.document);
this.data.document = null;
return results;
}