Skip to content

2.0.0 Unsolicited Suggestions for the Async API #2656

@CxRes

Description

@CxRes

Following @ryansolid streams, I find the work on managing Async Data in Solid 2.0 to be very impressive, and I am still trying to work out the implications of it. The UI (or the store powering it) indeed needs to track a current and future value during the course of an update. However, I feel the proposed UI is minimalist rather than being symmetric, which offends my physics sensibilities.

I'll start by observing that isPending(fn) is necessitated by the need to show to the consumer what is going on, often overlaid on the data itself. But I would argue that for consistency you should instead also have isLoading(), isErrored() as well.

Consider the UI where you want to show the data and status separately, might be far away from each other, say the status is next to a refresh button or on a status bar. The boundaries are not convenient for building such a UI, whereas the functions allow one to independently calculate and show the status (as well as possibly block a refresh button, if that's what the designer wants).

As far as the component boundaries are concerned (which I see as a common case convenience), I would suggest looking at it as a unified <AsyncSlot/> which should have an API like so:

<AsyncSlot
  loading={}
  pending={}
  errored={}
>
  <Page/>
</AsyncSlot>

with the <Page/> being shown for any undefined attributes.

Or even

<AsyncSlot
  loading={}
  loaded={}
  pending={}
  errored={}
/>

if you want to be super consistent. But the latter might not be ergonomic.

This will encourage developers to think about providing pending and errored states whenever they write a component with Async Data, rather than thinking of it as outside the component. Think of it as a psychological Nudge.

These changes are backwards compatible. Ideally, <Loading> and <Errored> should be made redundant, but that is a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions