Last active
May 11, 2018 13:22
-
-
Save mmintel/69b7f2630e48523bdecff7f810d402c4 to your computer and use it in GitHub Desktop.
Code snippets für eine Javascript Architektur
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Lade alle Module aus dem Ordner und speicher Sie in der Variable ab | |
| import * as modules from './modules'; | |
| class App { | |
| constructor() { | |
| // Speicher die Module in der App | |
| this.modules = {}; | |
| } | |
| init() { | |
| // Iteriere durch alle Module, führe jedes Modul aus und | |
| // übergebe die App (this) via Dependency Injection. | |
| Object.keys(modules).forEach((key) => { | |
| this.modules[key] = modules[key](this); | |
| }); | |
| } | |
| } | |
| // Wir haben nur eine App, also können wir sofort eine Instanz erzeugen | |
| const app = new App(); | |
| // Optional: die App in Window abspeichern, | |
| // damit wir zu Debbugging-Zwecken leicht aus der Browser Console darauf zugreifen können | |
| window.app = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment