{"id":16464971,"url":"https://github.com/sellmair/disposer","last_synced_at":"2025-08-30T07:03:50.481Z","repository":{"id":56264065,"uuid":"150860212","full_name":"sellmair/disposer","owner":"sellmair","description":"Easily dispose rxJava streams with Android's Lifecycle","archived":false,"fork":false,"pushed_at":"2020-11-17T20:29:33.000Z","size":177,"stargazers_count":175,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T23:44:46.020Z","etag":null,"topics":["android","disposable","kotlin","lifecycle","rxjava","rxjava2","rxjava3","rxlifecycle"],"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/sellmair.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-29T12:03:40.000Z","updated_at":"2024-10-29T05:40:59.000Z","dependencies_parsed_at":"2022-08-15T15:40:34.033Z","dependency_job_id":null,"html_url":"https://github.com/sellmair/disposer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/sellmair/disposer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellmair%2Fdisposer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellmair%2Fdisposer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellmair%2Fdisposer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellmair%2Fdisposer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sellmair","download_url":"https://codeload.github.com/sellmair/disposer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellmair%2Fdisposer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272815835,"owners_count":24997662,"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-08-30T02:00:09.474Z","response_time":77,"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":["android","disposable","kotlin","lifecycle","rxjava","rxjava2","rxjava3","rxlifecycle"],"created_at":"2024-10-11T11:31:03.453Z","updated_at":"2025-08-30T07:03:50.461Z","avatar_url":"https://github.com/sellmair.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Disposer\nEasily dispose RxJava streams with Android's Lifecycle\n\n![GitHub top language](https://img.shields.io/github/languages/top/sellmair/disposer.svg)\n[![Build Status](https://travis-ci.org/sellmair/disposer.svg?branch=master)](https://travis-ci.org/sellmair/disposer)\n![Bintray](https://img.shields.io/bintray/v/sellmair/sellmair/disposer.svg)\n\nCheckout my [Medium](https://medium.com/@sellmair/disposing-on-android-the-right-way-97bd55cbf970) article.\n\n### Usage\n\n##### Gradle\n\n```groovy\ndependencies {\n    // Non AndroidX projects\n    implementation 'io.sellmair:disposer:1.1.0'\n    \n    // AndroidX projects rxjava2\n    implementation 'io.sellmair:disposer:2.0.0'\n    \n    // AndroidX projects rxjava3    \n    implementation 'io.sellmair:disposer:3.0.0'\n}\n```\n\n\u003cbr\u003e\n\n##### Disposer\nA ```Disposer``` is the object managing multiple ```Disposable``` instances and disposes them\nat the correct time. \n\nYou can easily add a given disposable to a ```Disposer```:\n\n```kotlin\nval disposer: Disposer = /* ... */\nval disposable = Service.queryAwesomeData().subscribe()\ndisposer.add(disposable)  // The disposable will now managed by the disposer\n```\n\n\n\nOr a much sweeter apis, that might look familiar to rxKotlin users: \n\n```kotlin\nval disposer: Disposer = /* ... */\ndisposer += Service.queryAwesomeData().subscribe() // Managed by the disposer\n```\n\n```kotlin\nval disposer: Disposer = /* ... */\nService.queryAwesomeData().subscribe().disposeBy(disposer) // Managed by the disposer\n```\n\n\u003cbr\u003e\n\n##### Get the correct ```Disposer```\n\nRxLifecycle makes it easy to get a disposer for each lifecycle hook like \n```onCreate```,  ```onStart```, ```onResume```, ```onPause```, ```onStop``` and ```onDestroy```\n\n\nOne can simple call the extension function:\n\n```kotlin\nval onStopDisposer: Disposer = lifecycle.disposers.onStop\n```\n\n\nMuch more shorter and convenient extensions are also offered, like for LifecycleOwner:\n\n```kotlin\nclass MyCoolComponent: LifecycleOwner {\n    \n    // ...\n    \n    private val onStopDisposer: Disposer = this.onStop\n\n}\n```\n\nWhich leads to very concise and readable API's inside your ```Activity``` or ```Fragment``` classes:\n\n\n\u003cbr\u003e\n\n\n##### Example:\n\n```kotlin\nclass MyCoolFragment {\n    \n    // awesome other code \n    \n    fun onStart(){\n        super.onStart()\n        \n        awesomDataProvider.query()\n            .flatMap(::pepareForAwesomeness)\n            .filter(::isAwesome)\n            .subscribe(::displayAwesomeData)\n            .disposeBy(onStop) // \u003c---  Will automatically be disposed when onStop() is called.\n    }\n}\n```\n\n\n\n##### Advanced: Upstream dispose\n\nIt is also possible to put the ```.disposeBy``` call before the ```.subscribe```. \nBut be aware, that this will only dispose the upstream not the downstream, which is \noften okay, but should only be used with caution!\n\n```kotlin\nawesomDataProvider.query()\n    .flatMap(::pepareForAwesomeness)\n    .filter(::isAwesome)\n    .disposeBy(onStop) // \u003c--- Will dispose everything above it when .onStop() is called\n    .subscribe(::displayAwesomeData)\n```\n\n\n##### Create you own Disposer\n\nYou can easily create your own ```Disposer``` by calling\n\n```kotlin\nval disposer = Disposer.create()\n```\n\nEach call of \n```kotlin\ndisposer.dispose()\n```\n\nWill dispose all currently managed disposables and reset the ```Disposer```\n\n⚠️ Be aware: This behaviour differs from ```CompositeDisposable``` and actually\nis more like ```CompositeDisposable.clear```. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsellmair%2Fdisposer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsellmair%2Fdisposer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsellmair%2Fdisposer/lists"}