Node.js中自定义EventEmitter 的必要性
迷茫
迷茫 2017-04-17 13:08:19
0
2
624
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
迷茫

The problem that EventEmitter solves is that the time publisher does not need to care who is listening for the event, and the event listener does not care who sends the event, as long as they emit and on on the same EventEmitter object. Such a design will significantly reduce the connection between event publishers and listeners, thereby reducing complexity.

迷茫
  1. When your event sender and consumer are both in the same module, and there is no need to notify other modules or other modules to care about the events, you can use callback to complete the event sending/monitoring.

  2. The purpose of using EventEmitter is to reduce the coupling between modules
    Modules pay attention to EventEmitter rather than which module sends the event; at the same time, the module that sends the Event does not care that I send it. Whether there is a response to the event, and whether any module needs this event, this can make the responsibilities of the module clear, and each module only handles the work it should complete

  3. If it is a simple execute callback, then the party that sends the event/generates the event must know who I want to send the event to and which module's callback is called. Whenever a new module needs this event notification, it must be modified on the sending side, and the consuming event side cannot do anything

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!