Skip to content
This repository has been archived by the owner on Apr 20, 2020. It is now read-only.

Latest commit

 

History

History
27 lines (20 loc) · 622 Bytes

play-with-events.md

File metadata and controls

27 lines (20 loc) · 622 Bytes

Play with events

Publish events

Events are published from cqrs().publish(). Where publish take the payload and the metadata as arguments. Both are optionals.

cqrs().publish('eventName', payload, metdata);

Listen events

Events are listened from cqrs().on().invoke(). Where on takes the name of the event as parameter and invoke the callback.

The callback has two arguments:

  • the payload, it can be null
  • the metadata, it will be never null
cqrs().on('eventName').invoke(function (payload, metadata) {
    // do some stuff with payload and metadata
    // can return a promise
});