Skip to content

Instantly share code, notes, and snippets.

@mnichols
Created February 28, 2017 16:16
Show Gist options
  • Save mnichols/90fe7a0840e6e0b8e20aeb6ebb42f022 to your computer and use it in GitHub Desktop.
Save mnichols/90fe7a0840e6e0b8e20aeb6ebb42f022 to your computer and use it in GitHub Desktop.
var request = {
correlationId: '888',
commands: [{
command: 'makeComment',
contextId: '123',
text: 'foible',
commentId: '456'
}]
}
function makeCommentHandler(events, command) {
if (events.filter( e => e.commentId === command.commentId) > 0) {
throw new Error('hey you already assigned this id to a comment (rare)')
}
events.push({
event: 'commentMade',
text: command.text,
commentId: command.commentId,
contextId: command.contextId
})
return events
}
function samReadModelUpdater(event) {
if (event.event === 'commentMade') {
var context = getContext(event.contextId)
context.comments[event.commentId] = { text: event.text, commentId: event.commentId, timestamp: 'iso' }
save(context)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment