Last active
January 24, 2017 02:45
-
-
Save honewatson/90a3ae80c409fcfc04e22ed99fbe7f84 to your computer and use it in GitHub Desktop.
Basic ev manager
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
| class App { | |
| constructor() { | |
| this._listeners = {}; | |
| } | |
| ev(obj, listener) { | |
| return this._listeners[name](this, obj); | |
| } | |
| listener(name, func) { | |
| if(this._listeners[name]) { | |
| throw `${name} already exists`; | |
| } | |
| else { | |
| this._listeners[name] = func; | |
| } | |
| } | |
| listeners() { | |
| return Object.keys(this._listeners); | |
| } | |
| } | |
| const app = new App(); | |
| app.listener( | |
| 'hello', | |
| (app, obj) => | |
| console.log([app, obj])) | |
| app.ev('bingo gin', 'hello'); |
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
| class App { | |
| ev(obj, listener) { | |
| return this.ev[listener](this, obj); | |
| } | |
| } | |
| const app = new App(); | |
| app.ev.hello = (app, obj) => | |
| console.log([app, obj]); | |
| ev('bingo gin', 'hello'); |
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
| function evManager(app){ | |
| return function ev(obj, listener) { | |
| return ev[listener](app, obj); | |
| } | |
| } | |
| window.ev = evManager({hello:"world"}); | |
| ev.hello = (app, obj) => | |
| console.log([app, obj]); | |
| ev('bingo', 'hello'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment