yewstack/yewtil

Fetch Abstraction Feature

hgzimmerman opened this issue · 2 comments

Create a Monad / Component pair: FetchState, and Fetch respectively.

The end render code should look like:

html! {
    <Fetch<Data> state = self.fetch_state >
        <FetchSuccess render = |data| html!{data} />

        <FetchNotStarted>

        </FetchNotStarted>

        <FetchLoading>

        </FetchLoading>

        <FetchFailed render = |error| html!{error}/>
    </Fetch>
}

The problem with this is that type parameters need to be supplied to allow callbacks to bubble back up to the intended context, making defining the above structure very visually noisy and not particularly ergonomic.

If VNodes didn't have a Component type parameter to indicate what scope they are bound to, this might be able to be acomplished more ergonomically, but in reality, it might be easier to just supply Fetch with a Type parameter with some trait implemented for it instead of defining all of this inline.

I've settled on a verbose version where the Msg type of the callback needs to be supplied at all layers.