Get updates via , Github, or RSS | About

Episode 55: SPA - WebData Page Model Feb 28, 2018

As we add new pages to our application, and data to our model, the complexity and maintainability of our application increases. Using the RemoteData pattern, we can modify our page type to represent only the current, valid state of the app.

Examples

Main.elm

type Msg
    = TopStoriesFetched (WebData HomeModel)


type Page
    = Home (WebData HomeModel)


type alias HomeModel =
    { topStories : List StoryId }


type alias Model =
    { page : Page
    }


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        TopStoriesFetched webData ->
            ( { model | page = Home webData }, Cmd.none )