{"id":21824635,"url":"https://github.com/shopify/livedata-ktx","last_synced_at":"2025-04-05T14:08:47.542Z","repository":{"id":53958477,"uuid":"130487409","full_name":"Shopify/livedata-ktx","owner":"Shopify","description":"Kotlin extension for LiveData, chaining like RxJava","archived":false,"fork":false,"pushed_at":"2023-03-21T17:51:10.000Z","size":216,"stargazers_count":466,"open_issues_count":5,"forks_count":28,"subscribers_count":396,"default_branch":"master","last_synced_at":"2025-04-05T14:08:42.106Z","etag":null,"topics":["android","architecture-components","kotlin","livedata","rxjava"],"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/Shopify.png","metadata":{"files":{"readme":"README.1.x.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-04-21T15:36:05.000Z","updated_at":"2025-02-03T05:56:59.000Z","dependencies_parsed_at":"2025-01-15T03:54:02.887Z","dependency_job_id":"4c7daec5-b577-449c-8e45-ca56c9591a6d","html_url":"https://github.com/Shopify/livedata-ktx","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Flivedata-ktx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Flivedata-ktx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Flivedata-ktx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Flivedata-ktx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shopify","download_url":"https://codeload.github.com/Shopify/livedata-ktx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345854,"owners_count":20924102,"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":["android","architecture-components","kotlin","livedata","rxjava"],"created_at":"2024-11-27T17:59:25.828Z","updated_at":"2025-04-05T14:08:47.521Z","avatar_url":"https://github.com/Shopify.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg?maxAge=2592000)](https://raw.githubusercontent.com/shopify/livedata-ktx/master/LICENSE)\n[ ![Download](https://api.bintray.com/packages/shopify/shopify-android/livedata-ktx/images/download.svg) ](https://bintray.com/shopify/shopify-android/livedata-ktx/_latestVersion)\n[![Build Status](https://travis-ci.org/Shopify/livedata-ktx.svg?branch=master)](https://travis-ci.org/Shopify/livedata-ktx)\n\n# livedata-ktx\nKotlin extension for LiveData, chaining like RxJava\n\n\n# Getting Started\n\nTo add LiveData KTX to your project, add the following to your app module's build.gradle:\n\n```groovy\nimplementation \"com.shopify:livedata-ktx:VERSION\"\n```\n\n#### For `android.arch.lifecycle:livedata:1.x`, please use `com.shopify:livedata-ktx:1.x`\n#### For `androidx.lifecycle:livedata:2.x`, please use `com.shopify:livedata-ktx:2.x`\n\n*(Check https://github.com/Shopify/livedata-ktx/releases for more information)*\n\n\n# Usage\n\n\n### Chaining LiveData\n\n```kotlin\nval liveData: MutableLiveData\u003cBoolean\u003e = MutableLiveData()\nliveData\n  .distinct()\n  .filter { it == false }\n  .map { true }\n  .nonNull()\n  .observe(lifecycleOwner, { result -\u003e\n    // result is non-null and always true\n  })\n```\n\n### Remove observer\n\nBecause the input observer goes through a wrapper before it observes to source LiveData. So that you can't simply remove it by just calling origin method `liveData.removeObserver`.\n\nThe new observe method returns `Removable` interface that allows you to remove observer effectively.\n\n```kotlin\nval liveData: MutableLiveData\u003cBoolean\u003e = MutableLiveData()\nval removable = liveData\n  .nonNull()\n  .observe(lifecycleOwner, {\n    // TODO\n  })\nremovable.removeObserver()\n```\n\n### SingleLiveData\n\nIt is a lifecycle-aware observable that sends only new updates after subscription, used for events like navigation and Snackbar messages. `livedata-ktx` has different implementation comparing to SingleLiveEvent from [google samples android-architecture](https://github.com/googlesamples/android-architecture/blob/dev-todo-mvvm-live/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/SingleLiveEvent.java).\n\n```kotlin\nval liveData: MutableLiveData\u003cInt\u003e = SingleLiveData()\nval actuals: MutableList\u003cInt?\u003e = mutableListOf()\nval observer: (t: Int?) -\u003e Unit = { actuals.add(it) }\n\nliveData.value = 1\nliveData.observe(this, observer)\nliveData.value = 2\nliveData.value = 3\n\nval expecteds = mutableListOf(2, 3)\nassertEquals(expecteds, actuals)\n```\n\nFor more use cases, please see the tests at [LiveDataTest.kt](https://github.com/shopify/livedata-ktx/blob/master/livedata-ktx/src/test/java/com/shopify/livedataktx/LiveDataTest.kt)\n\n\n# Feel missing methods\n\nPlease suggest what you need by creating issues. I will support it as fast as I can.\n\n\n# Contributing\n\nAny contributions are welcome!  \nPlease check the [CONTRIBUTING](CONTRIBUTING.md) guideline before submitting a new issue. Wanna send PR? [Click HERE](https://github.com/shopify/livedata-ktx/pulls)\n\n# Maintainers\n\n- Francisco Cavedon \u003c[@fcavedon](https://github.com/fcavedon)\u003e\n- Henry Tao \u003c[@henrytao-me](https://github.com/henrytao-me)\u003e\n- Ivan Savytskyi \u003c[@sav007](https://github.com/sav007)\u003e\n- Kris Orr \u003c[@krisorr](https://github.com/krisorr)\u003e\n\n\n# License\n\n    The MIT License (MIT)\n\n    Copyright (c) 2018 Shopify Inc.\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopify%2Flivedata-ktx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshopify%2Flivedata-ktx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopify%2Flivedata-ktx/lists"}