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

Retain state while refreshing #40

Open
makenosound opened this issue Aug 25, 2020 · 6 comments
Open

Retain state while refreshing #40

makenosound opened this issue Aug 25, 2020 · 6 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@makenosound
Copy link

I’ve just started using this on a project and have a situation where I want to refresh the data after a change. At the moment it seems like there’s no easy way to differentiate these states:

  • Loading for the first time
  • Reloading after the initial fetch is successful

... and I wondered if there was scope to handle that in some way. Retaining the existing value of data would probably be enough I think (though I imagine that has flow-on effects that I am not seeing).

@rohan-deshpande
Copy link
Collaborator

Hey there, I might be misunderstanding but should there be a difference between your two points?

Currently refresh will always fetch the resource from remote meaning that it's a true refreshing of state. Could you possibly outline the differences you would expect to see between your two points in an application flow context?

Also, why would you want to retain the existing value of data if you also want to refresh that data?

@rohan-deshpande rohan-deshpande added the question Further information is requested label Aug 26, 2020
@makenosound
Copy link
Author

but should there be a difference between your two points?

Yep, it is subtle, but there is a difference. The scenario I’m looking at is:

  • A listResource loads 10 items sorted by date desc
  • A user deletes one of those items (which is removed with an optimistic update)
  • Refresh to fetch from the server with the latest data, which should gives us an additional item to replace the delete one.

With the current API there’s not an easy way to differentiate between the loading values for the refresh vs the initial load. And ideally in the scenario I’m describing we’d have a different initial loading state to one when most of the data is the same. Does that clarify?

A possible API could be to allow an argument to be passed to refresh that would retain any previous data until the new fetch completes.

@rohan-deshpande
Copy link
Collaborator

A possible API could be to allow an argument to be passed to refresh that would retain any previous data until the new fetch completes.

So if I understand correctly you don't want the hooked/subscribed component to go back to the loading state while the refresh is occurring, rather, you'd like the current data to be displayed until the fetch has completed?

@makenosound
Copy link
Author

you'd like the current data to be displayed until the fetch has completed?

That is correct, yep. A "stale while revalidate" if you will.

@rohan-deshpande
Copy link
Collaborator

Right! Okay, I think we did discuss this @albertogasparin, I think it shouldn't be too hard to add and I feel it might be a fairly common requirement from consumers.

@rohan-deshpande rohan-deshpande added the enhancement New feature or request label Sep 1, 2020
@rohan-deshpande rohan-deshpande changed the title Refreshing state Retain state while refreshing Sep 1, 2020
@makenosound
Copy link
Author

Awesome, thanks! It’s definitely something that can be done around the existing API, but it adds a fair bit of boilerplate and I can seem it being a behaviour I’d want to use regularly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants