Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.2 KB

event.md

File metadata and controls

56 lines (40 loc) · 1.2 KB

Event

Process of registering, listening and firing events.


Table of Contents


Listening

Things to consider:

  • If the event does not exist it automatically registers it, also you can set the count as well.
  • events are registered when there are active listeners

With <event-name> being the name you registered the event with, the callback being the function which is called with eventData and TEventData being the type of eventData, you can listen to an event by calling :

mediator.on<TEventData>(
    event-name: string,
    callback: (eventData: TEventData) => void,
    register? = false,
    register-count? = -1
  );

For example:

mediator.on("request", (data) => {
  console.log(`Requested: ${data}`);
});

Firing

With <event-name> being the name of the event, <event-data> being the eventData which is passed to listeners' callback and TEventData being the type of <event-data>, to fire an event:

  mediator.fire<TEventData>(
    event-name: string,
    event-data: TEventData
  );