Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome: Clear Post edits on save success #1092

Closed
wants to merge 1 commit into from
Closed

Conversation

youknowriad
Copy link
Contributor

Currently, we're clearing post edits when we trigger the post save request, this has the drawback of reverting the post state for a small period of time (try switching to private, you'll notice a flickering in the visibility while saving).

This PR moves clearing post edits to the save success handler, but at the same time, if we made other edits while saving, these new edits are kept in the store.

Related #945 (comment)

@youknowriad youknowriad self-assigned this Jun 9, 2017
@youknowriad youknowriad requested a review from aduth June 9, 2017 11:55
@aduth
Copy link
Member

aduth commented Jun 9, 2017

Curious if another option might work better: Rather than waiting 'til after the save and deciding then which keys should be omitted from edits, should we optimistically assume that the current saved value of the post should inherit those edited values as the "new truth", and continue as we were to clear edits immediately at the time of save? Becomes a bit tricky to manage if the save attempt fails, but we might be able to store a reference to the original post in the effect handler and revert back to it in such a case.

In any case, if we keep as is, can we add an inline comment reflecting this intent:

if we made other edits while saving, these new edits are kept in the store.

@youknowriad
Copy link
Contributor Author

youknowriad commented Jun 9, 2017

I think the solution here is simpler and works just as well. I've added the comment. Fine to revisit later. Merging

@youknowriad
Copy link
Contributor Author

Oh! Sorry for the confusion, I probably dismissed this feedback quickly. let me rephrase this. What benefits do you see in optimistically update the currentPost?

My thinking here is:

  • We'll need another reducer to store the previous saved post to make sure we could restore it if it fails.
  • Minor: What if another save action is triggered, should we store multiple previous posts? I know the UI forbids this for now.
  • I'm finding the current solution really simple and works great. We may be concerned about performance but I don't think we should because this is executed after an async request which in all cases would take way more time and this time is negligible.

@aduth
Copy link
Member

aduth commented Jun 9, 2017

Thanks for elaborating. My thinking was primarily two-fold:

  • Whether we generally treat the flow of data as optimistic or pessimistic. I'd argue the approach here is pessimistic: we wait until we hear back from the server before updating our representation of the post.
  • It's no longer simple when our action was previously "clear edits", and is now "clear edits, but only of these key value pairs where the value matching what we'd known to be the edit is still the edited value, otherwise keep the rest"

Not that optimistic updates aren't challenging. There are options though. redux-optimist looks interesting for this use case.

@youknowriad
Copy link
Contributor Author

This library looks awesome, I'll give it a try 👍

@youknowriad
Copy link
Contributor Author

replaced by #1093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants