MobileNativeFoundation / Store

A Kotlin Multiplatform library for building network-resilient applications
https://mobilenativefoundation.github.io/Store/
Apache License 2.0
3.18k stars 203 forks source link

[Feature Request] The stream of StoreResponse<T> should emit Loading(origin = SourceOfTruth) #566

Open FilippoVigani opened 1 year ago

FilippoVigani commented 1 year ago

Currently whenever we call Store.stream(StoreRequest.cached...)...) the only Loading we get is that of a Fetcher. This means that if we create a UI state folding the stream of StoreResponses, we can't really know when we are loading stuff from the SourceOfTruth, which is usually fast but not instant. Often we want to show a loading not only when we are fetching data but also while retrieving data from the source of truth.

The solution would be to add the emission of a Loading store response with the origin set to SourceOfTruth which retrieving data. This way we can be more granular the way we handle loading states.

Note: This refers to Store4 (4.0.5).

digitalbuddha commented 1 year ago

I think the initial concern was around disk emitting fairly quickly leading to ui flashing, I'm ok with this going in with some flag in the request that enables it. Let me think about a clean way to do it. Happy to accept a PR as well