move frontend app into separate file
This commit is contained in:
parent
bb411a1a28
commit
431d693e68
25
frontend/src/app.js
Normal file
25
frontend/src/app.js
Normal 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,27 +1,8 @@
|
|||||||
import { HttpClient } from './services/http-client/http-client';
|
import { App } from './app';
|
||||||
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 Utils from './utils/utils';
|
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();
|
export const app = new App();
|
||||||
|
app.registerUtilities(Utils);
|
||||||
|
|
||||||
// attach the app to window to be able to get a hold of the
|
// attach the app to window to be able to get a hold of the
|
||||||
// app instance from the shakespearean templates
|
// app instance from the shakespearean templates
|
||||||
|
|||||||
Reference in New Issue
Block a user