DEV Community

Discussion on: My first Elm app

Collapse
 
wolfadex profile image
Wolfgang Schuster

You can get Suspense like behavior with Elm fairly easily. Create a type:

type Request e d = Loading | Completed (Result e d)

And match it up with a simple view function:

suspense : Html msg -> (Result e d -> HTML msg) -> Request e d -> Html msg
suspense loadingHtml childHtml request =
    case request of
        Loading -> loadingHtml
        Completed result -> childHtml result

There are some handy packages that also help with giving you better types for your requests, such as package.elm-lang.org/packages/ohan...

Thread Thread
 
selbekk profile image
selbekk

Cool! Yeah that does emulate some of it!