From 431d693e686431512282659f314558957aef22bf Mon Sep 17 00:00:00 2001 From: Felix Hamann Date: Sun, 26 May 2019 21:07:23 +0200 Subject: [PATCH] move frontend app into separate file --- frontend/src/app.js | 25 +++++++++++++++++++++++++ frontend/src/main.js | 23 ++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 frontend/src/app.js diff --git a/frontend/src/app.js b/frontend/src/app.js new file mode 100644 index 000000000..6c7fa215f --- /dev/null +++ b/frontend/src/app.js @@ -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); + }); + } +} diff --git a/frontend/src/main.js b/frontend/src/main.js index 91ebb8e24..ada0b5890 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -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