Created
February 28, 2017 16:16
-
-
Save mnichols/90fe7a0840e6e0b8e20aeb6ebb42f022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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