{"id":28720322,"url":"https://github.com/pete-murphy/elm-loadable","last_synced_at":"2025-10-07T14:59:54.889Z","repository":{"id":296494412,"uuid":"993561945","full_name":"pete-murphy/elm-loadable","owner":"pete-murphy","description":"Loadable and reloadable data","archived":false,"fork":false,"pushed_at":"2025-06-02T21:01:24.000Z","size":98,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-30T02:46:31.960Z","etag":null,"topics":["elm","remote-data"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/pete-murphy/elm-loadable/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pete-murphy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-31T02:58:17.000Z","updated_at":"2025-06-15T20:16:49.000Z","dependencies_parsed_at":"2025-05-31T16:00:05.603Z","dependency_job_id":"3b109d09-d796-464d-9411-76f6085fa749","html_url":"https://github.com/pete-murphy/elm-loadable","commit_stats":null,"previous_names":["pete-murphy/elm-loadable"],"tags_count":1,"template":false,"template_full_name":"dillonkearns/elm-package-starter","purl":"pkg:github/pete-murphy/elm-loadable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pete-murphy%2Felm-loadable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pete-murphy%2Felm-loadable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pete-murphy%2Felm-loadable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pete-murphy%2Felm-loadable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pete-murphy","download_url":"https://codeload.github.com/pete-murphy/elm-loadable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pete-murphy%2Felm-loadable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278794401,"owners_count":26046968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","remote-data"],"created_at":"2025-06-15T07:00:12.914Z","updated_at":"2025-10-07T14:59:54.853Z","avatar_url":"https://github.com/pete-murphy.png","language":"Elm","readme":"# `pete-murphy/elm-loadable`\n\nA data type for tracking loadable (and reloadable) data, like data fetched from a backend server.\n\n## Installation\n\n```\nelm install pete-murphy/elm-loadable\n```\n\n## Design Goals\n\nThis package is centered around the `Loadable` type, which is a minimal extension of `RemoteData` from [`krisajenkins/remotedata`](https://package.elm-lang.org/packages/krisajenkins/remotedata/latest) that adds a \"reloading\" state to the error and success cases. See [this discussion on alternative solutions to this problem](https://github.com/krisajenkins/remotedata/issues/9) for background.\n\nThere are many other use cases for extensions on top of `RemoteData`—you might want to track how many times a request has been attempted, or you might want to attach metadata about when the data was last successfully loaded. The motivation for this package is simply to allow _showing stale data while refetching_.\n\n`Loadable e a` is essentially the same as `( Bool, Maybe (Result e a) )`. This could be encoded many different ways, for example as the sum type\n\n```elm\ntype Loadable e a\n    = NotAsked\n    | Loading\n    | Failure e\n    | FailureReloading e\n    | Success a\n    | SuccessReloading a\n```\n\nThe encoding in this package is intended to make pattern-matching as simple as possible. Using `Loadable.value` this will often look like\n\n```elm\ncase Loadable.value model of\n    Loadable.Empty -\u003e\n        -- ...\n\n    Loadable.Success success -\u003e\n        -- ...\n\n    Loadable.Failure failure -\u003e\n        -- ...\n```\n\nwith the option of matching on `Loadable.isLoading model` in any of the three branches as needed. See [usage](#usage).\n\n## Overview\n\n### Usage\n\n#### `init`\n\nTypically you will use `Loadable.notAsked` or `Loadable.loading` in your `init` function.\n\n```elm\ntype alias Model =\n    { todos : Loadable Http.Error (List Todo) }\n\n\ninit : ( Model, Cmd Msg )\ninit =\n    ({ todos = Loadable.loading }, fetchTodos )\n\n```\n\n#### `update`\n\nIn `update`, you can transition `Loadable` to loading using `Loadable.toLoading`.\n\n```elm\ntype Msg\n    = UserClickedFetchTodos\n    | BackendRespondedWithTodos (Result Http.Error (List Todo))\n\n\nupdate : Msg -\u003e Model -\u003e ( Model, Cmd Msg )\nupdate msg model =\n    case msg of\n        UserClickedFetchTodos -\u003e\n            ( { model | todos = Loadable.toLoading model.todos }, fetchTodos )\n\n        BackendRespondedWithTodos result -\u003e\n            ( { model | todos = Loadable.fromResult result }, Cmd.none )\n\n```\n\n#### `view`\n\nIn `view` you can match on empty, success, and failure cases with `Loadable.value`, and separately match on `Loadable.isLoading` as needed.\n\n```elm\nview : Model -\u003e Html Msg\nview model =\n    Html.div []\n        [ Html.h1 [] [ Html.text \"Todos\" ]\n        , Html.button [ Events.onClick UserClickedFetchTodos ] [ Html.text \"Fetch Todos\" ]\n        , Html.div [ Attributes.classList [ ( \"loading\", Loadable.isLoading model.todos ) ] ]\n            [ case Loadable.value model.todos of\n                Loadable.Empty -\u003e\n                    Html.text \"Loading...\"\n\n                Loadable.Success todos -\u003e\n                    Html.ul [] (List.map viewTodo todos)\n\n                Loadable.Failure _ -\u003e\n                    Html.text \"Something went wrong\"\n            ]\n        ]\n```\n\n[See this example on Ellie](https://ellie-app.com/vBQPV95Fbdba1)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpete-murphy%2Felm-loadable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpete-murphy%2Felm-loadable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpete-murphy%2Felm-loadable/lists"}