mitt icon indicating copy to clipboard operation
mitt copied to clipboard

Mitt - some problems

Open lk101 opened this issue 2 years ago • 1 comments

I found some problems with mitt. Will these problems be considered in the future?

const emitter = mitt();
emitter.on("evt", () => {});
emitter.on("evt", () => { throw "some error." })
emitter.on("evt", () => { /** do something... */ })

while the

emitter.emit("evt");

happen, there is no chance to run the third callback.

Also,

emitter.on("evt", () => { emitter.off("evt") });
emitter.on("evt", () => { /** do something... */});
emitter.on("evt", () => { emitter.off("*") });
emitter.on("*", () => { /** do something... */});
emitter.on("*", () => { /** do something... */});
emitter.on("*", () => { /** do something... */});

while the

emitter.emit("evt");

happen, there is no chance to run the "*" callback, but can run the second "evt" callback.

Also,

mitt not supports

emitter.off(); // off all of the listeners.

lk101 avatar Jul 08 '22 09:07 lk101

off() is only really supported by Vue IIRC, whereas this API is more in line with Node's EventEmitter.

The error propagation is a good point. I will have to check what Node does (I believe it propagates synchronously like Mitt).

developit avatar Oct 25 '22 02:10 developit