From 770d60ead65acda05bbf6c494486e8e3fcfca06d Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sat, 26 May 2018 16:07:31 +0300 Subject: [PATCH] chain voting promises --- web/app/components/comment/comment.jsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx index 6ed56d94..97aaf800 100644 --- a/web/app/components/comment/comment.jsx +++ b/web/app/components/comment/comment.jsx @@ -18,6 +18,8 @@ export default class Comment extends Component { editTimeLeft: null, }; + this.votingPromise = Promise.resolve(); + this.updateState(props); this.decreaseScore = this.decreaseScore.bind(this); @@ -197,9 +199,13 @@ export default class Comment extends Component { score: score + 1, }); - api.vote({ id, url, value: 1 }).then(() => { - api.getComment({ id }).then(comment => store.replaceComment(comment)); - }); + this.votingPromise = this.votingPromise + .then(() => { + return api.vote({ id, url, value: 1 }) + .then(() => { + api.getComment({ id }).then(comment => store.replaceComment(comment)); + }); + }); } decreaseScore() { @@ -214,9 +220,13 @@ export default class Comment extends Component { score: score - 1, }); - api.vote({ id, url, value: -1 }).then(() => { - api.getComment({ id }).then(comment => store.replaceComment(comment)); - }); + this.votingPromise = this.votingPromise + .then(() => { + return api.vote({ id, url, value: -1 }) + .then(() => { + api.getComment({ id }).then(comment => store.replaceComment(comment)); + }); + }); } onReply(...rest) {