{"id":19195932,"url":"https://github.com/mercari/remotedatak","last_synced_at":"2025-05-09T00:33:42.915Z","repository":{"id":37469621,"uuid":"153220341","full_name":"mercari/RemoteDataK","owner":"mercari","description":"Algebraic data type (ADT) to represent the state of data that is loading from/to remote sources/destinations","archived":false,"fork":false,"pushed_at":"2023-07-07T13:22:08.000Z","size":277,"stargazers_count":43,"open_issues_count":7,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-04T11:05:27.486Z","etag":null,"topics":["adt","algebraic-data-types","android","functional-programming","java","kotlin","kotlin-android","kotlin-library","remote-data","remotedata"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/mercari.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2018-10-16T03:59:56.000Z","updated_at":"2025-01-15T15:19:55.000Z","dependencies_parsed_at":"2024-11-09T12:12:04.472Z","dependency_job_id":null,"html_url":"https://github.com/mercari/RemoteDataK","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercari%2FRemoteDataK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercari%2FRemoteDataK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercari%2FRemoteDataK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercari%2FRemoteDataK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mercari","download_url":"https://codeload.github.com/mercari/RemoteDataK/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171166,"owners_count":21865275,"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","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":["adt","algebraic-data-types","android","functional-programming","java","kotlin","kotlin-android","kotlin-library","remote-data","remotedata"],"created_at":"2024-11-09T12:12:00.446Z","updated_at":"2025-05-09T00:33:42.876Z","avatar_url":"https://github.com/mercari.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RemoteData for Kotlin\n\n[![jcenter](https://api.bintray.com/packages/mercari-inc/maven/remotedatak/images/download.svg)](https://bintray.com/mercari-inc/maven/remotedatak/_latestVersion) \n[![Build Status](https://circleci.com/gh/mercari/RemoteDataK.svg?style=svg)](https://circleci.com/gh/mercari/RemoteDataK)\n\nAlgebraic data type (ADT) to represent the state of data that is loading from/to remote sources/destinations\n\n## Setup\n\n```kotlin\ndependencies {\n  repositories {\n    jcenter()\n  }\n}\n\nimplementation(\"com.mercari.remotedata:remotedata:\u003clatest-version\u003e\")\n```\n\n## About\n\nRemoteData is useful to represent the state of data, when it is loading from/to a remote source/destination.\n\nUsing RemoteData is pretty straightforward, it is however meant to be used in a functional style.\n\nRemoteData works nicely with [RxJava](https://github.com/ReactiveX/RxJava) and [RxRedux](https://github.com/mercari/RxRedux), however it can be used independently.\n\nThis is done through 4 types: `Initial`, `Loading`, `Success` and `Failure`.\n\n- `Initial` represents the initial state of the data before any progress has been made.\n\n- `Loading` represents the intermediary loading state of data.\n\n- `Success` represents the state where the loading is completed, and holds the resulting value of the data.\n\n- `Failure` represents the state where the loading failed, and holds information about the reason of failure with an Exception. \n\nIn cases where the data size is known, you may find the properties `progress` and `totalUnits` of the `Loading` type useful.\nThe value of `progress` is always between `0` and `totalUnits` (default of `100` for percentages). \n\n`Initial` and `Loading` are `Incomplete`, whereas `Success` and `Failure` are `Complete`.\n\n## Usage\n\nA common use case for RemoteData would be mapping it into a UI transition or component state.\n\nFor example, when making a network request to fetch data, most UIs have a progress indicator and finally display the result.\n\n- Declare your data where you need it, where V is the type of data value and E the type of Exception/Error.\n\n```kotlin\nvar data: RemoteData\u003cV, E\u003e = Initial\n\n```\n\n- Once the data starts to load, transition to `Loading` with the optional setting of a `progress` and `totalUnits`.\n\n```kotlin\ndata = Loading()\n```\n\nIf `progress` is used, simply update it when required.\n\n```kotlin\ndata.progress = data.progress?.let { it + delta }\n```\n\n- Once the loading is complete successfully, transition to `Success` along with the actual data.\n\n```kotlin\ndata = Success(value)\n```\n\n- Otherwise, transition to `Failure` with a proper `Exception`.\n\n```kotlin\ndata = Failure(Exception(\"error\"))\n```\n\n- Behaviour based on the data state can then be mapped neatly, wherever the data is processed.\n```kotlin\nwhen (data) {\n    is Initial -\u003e initialize()\n    is Loading -\u003e progress(data.progress)\n    is Success -\u003e success(data.value) \n    is Failure -\u003e failure(data.error)\n }\n```\n\nOr with the other conveniences:\n\n```kotlin\nwhen {\n    data.isIncomplete -\u003e showProgress()\n    data.isComplete -\u003e hideProgress()\n }\n```\n\n### Higher oder functions\n\nA few higher order functions are also provided for convenience such as:\n\n- map\n- mapError\n- mapBoth\n- getOrElse\n- flatMap\n- flatMapError\n- fanout\n\nFor examples, take a look at some of the comprehensive [tests](https://github.com/mercari/RemoteData/blob/master/remotedata/src/test/java/com/mercari/remotedata/RemoteDataTest.kt).\n\n## Contribution\n\nPlease read the CLA below carefully before submitting your contribution.\n\nhttps://www.mercari.com/cla/\n\n## License\n\nCopyright 2018-2019 Mercari, Inc.\n\nLicensed under the MIT License. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmercari%2Fremotedatak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmercari%2Fremotedatak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmercari%2Fremotedatak/lists"}