Unliking a post updates like count on front end#12140
Merged
Gargron merged 7 commits intomastodon:masterfrom Oct 24, 2019
NimaBoscarino:master
Merged
Unliking a post updates like count on front end#12140Gargron merged 7 commits intomastodon:masterfrom NimaBoscarino:master
Gargron merged 7 commits intomastodon:masterfrom
NimaBoscarino:master
Conversation
when unfavouriting a status
Member
|
I'm sorry, but there is a reason why an asynchronous worker is used. Yes, your code returns the real state, but does so by running a lot of tasks (including networking) within the request/response cycle. If connection drops in the middle, the unfavourite operation could miss some instructions. It would be far easier to update the favourites count in the Redux reducer on the client-side. |
Contributor
Author
|
Thanks for the feedback! I'll undo the changes that I made, and I'll do it on the Redux reducer side instead. |
Contributor
Author
|
Okay, I did it through the reducer on the client-side! Does this look better? |
Gargron
reviewed
Oct 15, 2019
| return state.setIn([action.status.get('id'), 'favourited'], true); | ||
| case UNFAVOURITE_SUCCESS: | ||
| const favouritesCount = action.status.get('favourites_count'); | ||
| return state.setIn([action.status.get('id'), 'favourites_count'], favouritesCount - 1); |
Member
There was a problem hiding this comment.
A more concise way of writing this is:
return state.updateIn([action.status.get('id'), 'favourites_count'], x => Math.max(x - 1, 0));
Gargron
approved these changes
Oct 15, 2019
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the issue outlined by #9638.
Previous behaviour:
New behaviour: