April 2020
Intermediate to advanced
292 pages
6h 50m
English
Let’s handle that NameVideo command in the video-publishing Component:
| | function createHandlers ({ messageStore }) { |
| | return { |
| | NameVideo: command => { |
| ① | const context = { |
| | command: command, |
| | messageStore: messageStore |
| | } |
| | |
| | return Bluebird.resolve(context) |
| ② | .then(loadVideo) |
| | .then(ensureCommandHasNotBeenProcessed) |
| | .then(ensureNameIsValid) |
| | .then(writeVideoNamedEvent) |
| ③ | .catch(CommandAlreadyProcessedError, () => {}) |
| ④ | .catch( |
| | ValidationError, |
| | err => writeVideoNameRejectedEvent(context, err.message) |
| | ) |
| | }, |
| | // ... |
| | } |
| | } |
First, build a context consisting of the command in question and the messageStore.