emmett
emmett copied to clipboard
Event names enumerator
Can we add some option to enumerate all possible event names?
This is valuable because:
- users will have an official place to check for possible
emitoptions - 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...
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.