Skip to content

Instantly share code, notes, and snippets.

@honewatson
Last active January 24, 2017 02:45
Show Gist options
  • Select an option

  • Save honewatson/90a3ae80c409fcfc04e22ed99fbe7f84 to your computer and use it in GitHub Desktop.

Select an option

Save honewatson/90a3ae80c409fcfc04e22ed99fbe7f84 to your computer and use it in GitHub Desktop.
Basic ev manager
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');
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');
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