emmett icon indicating copy to clipboard operation
emmett copied to clipboard

Event names enumerator

Open ivan-kleshnin opened this issue 10 years ago • 1 comments

Can we add some option to enumerate all possible event names?

This is valuable because:

  1. users will have an official place to check for possible emit options
  2. we get errors when event name is mistyped

Something like:

import Emmett from "emmett";

let emitter = new Emmett([
  "scale.mouseDown"
]);

emitter.on("scale.mouseDown", (data) => {
  console.log("scale.mouseDown!");
});

emitter.emit("scale.mouseDown"); // CONSOLE.LOG
emitter.emit("scale.mouseUp"); // ERROR!

I don't know how it's better to adopt this to custom emitters (inheritance) but there are some ways...

ivan-kleshnin avatar Aug 10 '15 09:08 ivan-kleshnin

That sounds useful indeed. Currently, Emmett's constructor does not take any argument, so I'd rather pass it an optional options object potentially containing this restriction, just to make it easier to give it other params in the future.

jacomyal avatar Aug 10 '15 09:08 jacomyal