move frontend app into separate file

This commit is contained in:
Felix Hamann 2019-05-26 21:07:23 +02:00
parent bb411a1a28
commit 431d693e68
2 changed files with 27 additions and 21 deletions

25
frontend/src/app.js Normal file
View File

@ -0,0 +1,25 @@
import { HttpClient } from './services/http-client/http-client';
import { HtmlHelpers } from './services/html-helpers/html-helpers';
import { I18n } from './services/i18n/i18n';
import { UtilRegistry } from './services/util-registry/util-registry';
export class App {
httpClient = new HttpClient();
htmlHelpers = new HtmlHelpers();
i18n = new I18n();
utilRegistry = new UtilRegistry();
constructor() {
this.utilRegistry.setApp(this);
}
registerUtilities(utils) {
if (!Array.isArray(utils)) {
throw new Error('Utils are expected to be passed as array!');
}
utils.forEach((util) => {
this.utilRegistry.register(util);
});
}
}

View File

@ -1,27 +1,8 @@
import { HttpClient } from './services/http-client/http-client';
import { HtmlHelpers } from './services/html-helpers/html-helpers';
import { I18n } from './services/i18n/i18n';
import { UtilRegistry } from './services/util-registry/util-registry';
// import utils
import { App } from './app';
import Utils from './utils/utils';
class App {
httpClient = new HttpClient();
htmlHelpers = new HtmlHelpers();
i18n = new I18n();
utilRegistry = new UtilRegistry();
constructor() {
this.utilRegistry.setApp(this);
Utils.forEach(util => {
this.utilRegistry.register(util);
});
}
}
export const app = new App();
app.registerUtilities(Utils);
// attach the app to window to be able to get a hold of the
// app instance from the shakespearean templates