Notices

Obviously, Event Aggregator removes the pain of both memory management and object reference management by helping you remove dependencies between components. This is also known as Decoupling. Nevertheless, this technique also has some drawbacks. When decoupling components, you assure that your listening function will be called when its associated event happens, but you may have no idea of which underlying component caused the event to get dispatched. Even if you are debugging, you will have to go through a very long call-stack to find the dispatching root. Considering NodeJS is an encouraged asynchronous environment whose async counterparts make debugging harder, i.e call-stack usually lead to nothing. So you should only use Event Aggregator when the need for decoupling is real. Do not abuse it.

Another good practice is to avoid using Event Aggregator with components in the same layer. For e.g two UI elements in Presentation layer should not 'listen' to each other via Event Aggregator. Instead, let them communicate directly. Using Event Aggregator for components in the same layer may quickly come up with too many events being introduced. Thus obscures logic inside that layer and of course, makes it harder to debug and maintain. The communication via Event Aggregator should only be done between two components in different layers. For e.g some UI elements in Presentation listen to changes on some Models in Domain / Business Logic.

Last updated