Skip to content

[Proposal] Simplify StoreResponse by Replacing Loading and NoNewData with a isFetcherActive flag in Data #230

Closed

Description

@eyalgu

API update proposal:

Some of the alpha feedback we've gotten is that there are too many states to handle under StoreResponse.

We currently have the following
Loading
NoNewData
Data
Error.Message
Error.Exception

I propose we drop Loading and NewNewData and instead add a isFetcherActive flag to Data (and maybe also Error) that can be used by the users to know whether to show a spinner (or whatever they are using the loading flag for right now).

The isFetcherActive will only mirror the state of the original fetch associated with the stream and will not flip back and forth if subsequent steam calls are made that re-trigger the fetcher (thus preserving the existing Loading/NoNewData behavior)

As a bonus this will also eliminate the 2 states of StoreResponse that are only valid for origin=fetcher.

Activity

  1. added
    enhancement
    discussion
    on Sep 17, 2020
  2. changed the title [-][Proposal] Simplify StoreResponse by Replacing Loading and NoNewData with a `isFetcherAcive` flag in Data[/-] [+][Proposal] Simplify StoreResponse by Replacing Loading and NoNewData with a `isFetcherActive` flag in Data[/+] on Sep 17, 2020
  3. ferinagy commented on Sep 17, 2020

    @ferinagy
    Contributor

    While we are removing states, why do we need 2 error states? I think after quick look, I did not even find Error.Message used anywhere. IMO one error state with a throwable would suffice.

  4. eyalgu commented on Sep 17, 2020

    @eyalgu
    ContributorAuthor

    While we are removing states, why do we need 2 error states? I think after quick look, I did not even find Error.Message used anywhere. IMO one error state with a throwable would suffice.

    I've open #231 for discussing the error states. we do need to handle non throwable error propagation because we don't want to force our users to have to use exceptions to propagate errors.

  5. ferinagy commented on Sep 17, 2020

    @ferinagy
    Contributor

    and maybe also Error

    Is there a case when a first response in the stream would be an Error and there would be still fetch happening? I thought that would not be possible?

    The isFetcherActive will only mirror the state of the original fetch associated with the stream and will not flip back and forth...

    To avoid this confusion, maybe we could, instead of adding a flag, add a new state DataWhileLoading (help with better name appreciated), that would be only emitted as a first state. That way, we don't get tempted with checking isFetcherActive on the subsequent Data states.

  6. yigit commented on Sep 20, 2020

    @yigit
    Collaborator

    this feels like making stream not a stream of events anymore. Feels very similar to what we wanted to do very early on and we decided not to since this information can be kept with a simple stream fold operation.
    My first instinct is to implement the helper to do this and then the helper can have the logic.

    something like.

    data class UIState<T>(
        val loading:Boolean,
        val data: T?,
        val error:Throwable
    )
    

    The helper would handle restart of the stream (using the trigger mentioned in #124 ) but also keep previous data.

    Usage would be like:

    helper.flow.collect { uiState : UIState ->
    }
    
    refreshButton.onClick {
        helper.refresh()
    }
    
  7. yigit commented on Sep 20, 2020

    @yigit
    Collaborator

    here is a quick and dirty prototype:

    5bd4e27

  8. digitalbuddha commented on Nov 16, 2021

    @digitalbuddha
    Contributor

    I'm a fan of externalizing the UIState controller similar to what Yigit proposed above. Closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions