All Projects → sellmair → Disposer

sellmair / Disposer

Licence: mit
Easily dispose rxJava streams with Android's Lifecycle

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Disposer

Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+3757.39%)
Mutual labels:  rxjava, rxjava2, lifecycle
Rxlifecycle
Rx binding of stock Android Activities & Fragment Lifecycle, avoiding memory leak
Stars: ✭ 131 (-25.57%)
Mutual labels:  rxjava, rxjava2, lifecycle
Vertx Mqtt
Vert.x MQTT
Stars: ✭ 117 (-33.52%)
Mutual labels:  rxjava, rxjava2
Okhttp Okgo
OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Stars: ✭ 10,407 (+5813.07%)
Mutual labels:  rxjava, rxjava2
Reactivebeacons
Android library scanning BLE beacons nearby with RxJava
Stars: ✭ 171 (-2.84%)
Mutual labels:  rxjava, rxjava2
Featureadapter
FeatureAdapter (FA) is an Android Library providing an optimized way to display complex screens on Android.
Stars: ✭ 112 (-36.36%)
Mutual labels:  rxjava, rxjava2
Mvvm Architecture
The practice of MVVM + Jetpack architecture in Android.
Stars: ✭ 1,634 (+828.41%)
Mutual labels:  rxjava, lifecycle
Vertx Rx
Reactive Extensions for Vert.x
Stars: ✭ 137 (-22.16%)
Mutual labels:  rxjava, rxjava2
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (-55.11%)
Mutual labels:  rxjava, rxjava2
Dagger2
Kotlin Dagger2 example project
Stars: ✭ 145 (-17.61%)
Mutual labels:  rxjava, rxjava2
Android Clean Architecture Boilerplate
Apply clean architecture on Android
Stars: ✭ 141 (-19.89%)
Mutual labels:  rxjava, rxjava2
Rxwear
⌚️ Reactive Wearable API Library for Android and RxJava
Stars: ✭ 163 (-7.39%)
Mutual labels:  rxjava, rxjava2
Mvpframes
整合大量主流开源项目并且可高度配置化的 Android MVP 快速集成框架,支持 AndroidX
Stars: ✭ 100 (-43.18%)
Mutual labels:  rxjava, rxjava2
Rxlife
使用Jetpack、Kotlin实现的RxJava自动注销库,你值得拥有!
Stars: ✭ 92 (-47.73%)
Mutual labels:  rxjava, rxjava2
Reactivesensors
Android library monitoring device hardware sensors with RxJava
Stars: ✭ 161 (-8.52%)
Mutual labels:  rxjava, rxjava2
Freesound Android
Unofficial Android client for the Freesound Project
Stars: ✭ 81 (-53.98%)
Mutual labels:  rxjava, rxjava2
Jd Mall Master
一款高仿京东商城的UI,基于MVP的Retrofit2(okhttp3)+rxjava+dagger2+greendao+glide。该项目系仿京东商城,属于独立开发者作品,仅供参考学习,拒绝做一切商业用途,如有侵权,请告知删除
Stars: ✭ 151 (-14.2%)
Mutual labels:  rxjava, rxjava2
S Mvp
🔥🔥优化版MVP,使用注解泛型简化代码编写,使用模块化协议方便维护,APT过程使用注解解析器利用JavaPoet🌝完成重复模块的编写,利用ASpect+GradlePlugin 完成横向AOP编程+Javassist动态字节码注入+Tinker实现热修复+Retrofit实现优雅网络操作+RxJava轻松玩转数据处理
Stars: ✭ 1,095 (+522.16%)
Mutual labels:  rxjava, lifecycle
Aiyagirl
🔥 爱吖妹纸(含 Kotlin 分支版本)——Retrofit + RxJava + MVP 架构 APP 体验代码家的干货集中营 Gank.io,福利多多,不容错过
Stars: ✭ 1,109 (+530.11%)
Mutual labels:  rxjava, rxjava2
Rxjavapriorityscheduler
RxPS - RxJavaPriorityScheduler - A RxJava Priority Scheduler library for Android and Java applications
Stars: ✭ 138 (-21.59%)
Mutual labels:  rxjava, rxjava2

Disposer

Easily dispose RxJava streams with Android's Lifecycle

GitHub top language Build Status Bintray

Checkout my Medium article.

Usage

Gradle
dependencies {
    // Non AndroidX projects
    implementation 'io.sellmair:disposer:1.1.0'
    
    // AndroidX projects rxjava2
    implementation 'io.sellmair:disposer:2.0.0'
    
    // AndroidX projects rxjava3    
    implementation 'io.sellmair:disposer:3.0.0'
}

Disposer

A Disposer is the object managing multiple Disposable instances and disposes them at the correct time.

You can easily add a given disposable to a Disposer:

val disposer: Disposer = /* ... */
val disposable = Service.queryAwesomeData().subscribe()
disposer.add(disposable)  // The disposable will now managed by the disposer

Or a much sweeter apis, that might look familiar to rxKotlin users:

val disposer: Disposer = /* ... */
disposer += Service.queryAwesomeData().subscribe() // Managed by the disposer
val disposer: Disposer = /* ... */
Service.queryAwesomeData().subscribe().disposeBy(disposer) // Managed by the disposer

Get the correct Disposer

RxLifecycle makes it easy to get a disposer for each lifecycle hook like onCreate, onStart, onResume, onPause, onStop and onDestroy

One can simple call the extension function:

val onStopDisposer: Disposer = lifecycle.disposers.onStop

Much more shorter and convenient extensions are also offered, like for LifecycleOwner:

class MyCoolComponent: LifecycleOwner {
    
    // ...
    
    private val onStopDisposer: Disposer = this.onStop

}

Which leads to very concise and readable API's inside your Activity or Fragment classes:


Example:
class MyCoolFragment {
    
    // awesome other code 
    
    fun onStart(){
        super.onStart()
        
        awesomDataProvider.query()
            .flatMap(::pepareForAwesomeness)
            .filter(::isAwesome)
            .subscribe(::displayAwesomeData)
            .disposeBy(onStop) // <---  Will automatically be disposed when onStop() is called.
    }
}
Advanced: Upstream dispose

It is also possible to put the .disposeBy call before the .subscribe. But be aware, that this will only dispose the upstream not the downstream, which is often okay, but should only be used with caution!

awesomDataProvider.query()
    .flatMap(::pepareForAwesomeness)
    .filter(::isAwesome)
    .disposeBy(onStop) // <--- Will dispose everything above it when .onStop() is called
    .subscribe(::displayAwesomeData)
Create you own Disposer

You can easily create your own Disposer by calling

val disposer = Disposer.create()

Each call of

disposer.dispose()

Will dispose all currently managed disposables and reset the Disposer

⚠️ Be aware: This behaviour differs from CompositeDisposable and actually is more like CompositeDisposable.clear.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].