Created
November 26, 2017 17:12
-
-
Save JeffML/e8bcbb26240d6813e9c79316267aaf88 to your computer and use it in GitHub Desktop.
Resolver code for PostOps
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
const voteHandler = (postId, updown) => { | |
return new Promise((resolve, reject) => { | |
const post = posts.find(p => p.id === postId); | |
if (!post) { | |
reject(`Couldn't find post with id ${postId}`); | |
} | |
post.votes += updown; | |
resolve(post); | |
}) | |
}; | |
const PostOps = | |
({ | |
upvote: ({ | |
postId | |
}) => voteHandler(postId, 1), | |
downvote: ({ | |
postId | |
}) => voteHandler(postId, -1) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment