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) · 630 Bytes

play-with-commands.md

File metadata and controls

27 lines (20 loc) · 630 Bytes

Play with commands

Send commands

Commands are sent from cqrs().send(). Where send take the payload and the metadata as arguments. Both are optionals.

cqrs().send('commandName', payload, metdata);

Handle commands

Commands are handled from cqrs().handle().invoke(). Where handle takes the name of the command 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().when('commandName').invoke(function (payload, metadata) {
    // do some stuff with payload and metadata
    // can return a promise
});