How do you describe the difference between
- Special Event Based Messaging System
- manually trigger DOM events.
The first way to use events to send messages. An example would be to create an EventEmitter
The latter is just a way to manually use browsers in the DOM event system. This is mainly used by the DOM 3 Event API , which originally exists in (competent / modern) browsers.
So the question is, what do you want to do? Fire DOM or use events to send messages?
Test showing DOM 3 custom events 98% slower
The DOM seems to have huge overhead. He does this because he supports the dissemination of events and the bubbling. This is because it supports event bindings to DOMElement.
If you do not need any functions of DOM3 events, use the pub / sub library.
[Change 2]
As for error handling, how you handle error handling is up to you. If you know that your emitter event is synchronous, then this is the intended behavior. Either do your own error handling, or use setTimeout to make it asynchronous.
Be careful: if you make it asynchronous, you will lose the guarantee that the event handlers executed their logic after returning the emit / trigger / dispatch call. This requires a completely different high-level design, and then the assumption that the event emitters are synchronous. It is not a choice to make lightly
source share