Skip to content

Instantly share code, notes, and snippets.

@shiv19
Last active July 24, 2018 23:00
Show Gist options
  • Save shiv19/50ea515932d8cdee9e1eb04809e4fa8a to your computer and use it in GitHub Desktop.
Save shiv19/50ea515932d8cdee9e1eb04809e4fa8a to your computer and use it in GitHub Desktop.
Event emitter one liner
M=(o={})=>({on:(e,f)=>(o[e]=o[e]||[]).push(f),trigger:(e,d)=>(o[e]||[]).map(x=>x(d))});
m = M();
m.on("foo", (c) => console.log(c)); //register
m.trigger("foo",4) //invoke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment