DisposeOnDestroy

RxJava2 helper to dispose Disposables before leaking stuff

License

License

Categories

Categories

RxJava Container Microservices Reactive libraries
GroupId

GroupId

pl.mg6.rxjava2.disposeondestroy
ArtifactId

ArtifactId

core
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

DisposeOnDestroy
RxJava2 helper to dispose Disposables before leaking stuff
Project URL

Project URL

https://github.com/mg6maciej/DisposeOnDestroy
Source Code Management

Source Code Management

https://github.com/mg6maciej/DisposeOnDestroy

Download core

How to add to project

<!-- https://jarcasting.com/artifacts/pl.mg6.rxjava2.disposeondestroy/core/ -->
<dependency>
    <groupId>pl.mg6.rxjava2.disposeondestroy</groupId>
    <artifactId>core</artifactId>
    <version>0.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/pl.mg6.rxjava2.disposeondestroy/core/
implementation 'pl.mg6.rxjava2.disposeondestroy:core:0.1.0'
// https://jarcasting.com/artifacts/pl.mg6.rxjava2.disposeondestroy/core/
implementation ("pl.mg6.rxjava2.disposeondestroy:core:0.1.0")
'pl.mg6.rxjava2.disposeondestroy:core:aar:0.1.0'
<dependency org="pl.mg6.rxjava2.disposeondestroy" name="core" rev="0.1.0">
  <artifact name="core" type="aar" />
</dependency>
@Grapes(
@Grab(group='pl.mg6.rxjava2.disposeondestroy', module='core', version='0.1.0')
)
libraryDependencies += "pl.mg6.rxjava2.disposeondestroy" % "core" % "0.1.0"
[pl.mg6.rxjava2.disposeondestroy/core "0.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
io.reactivex.rxjava2 : rxjava jar 2.0.7

Project Modules

There are no modules declared in this project.

DisposeOnDestroy

RxJava2 helper to dispose Disposables before leaking stuff

Usage

Observable::disposeOnDestroy(Activity)
Single::disposeOnDestroy(Activity)
Maybe::disposeOnDestroy(Activity)
Completable::disposeOnDestroy(Activity)
class MyActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.my_activity)
        makeApiCall()
    }

    private fun makeApiCall() {
        myRetrofitApi.call()
                .subscribeOn(io())
                .observeOn(mainThread())
                .disposeOnDestroy(this)
                .subscribe(this::displayResults, this::displayError)
    }

    // ...
}

Also works with Fragments from support-v4.

Observable::disposeOnDestroyView(Fragment)
Single::disposeOnDestroyView(Fragment)
Maybe::disposeOnDestroyView(Fragment)
Completable::disposeOnDestroyView(Fragment)
class MyFragment : Fragment() {

    // ...

    private fun onSearchClick(query: String) {
        searchApi.call(query)
                .subscribeOn(io())
                .observeOn(mainThread())
                .disposeOnDestroyView(this)
                .subscribe(this::displayResults, this::displayError)
    }

    // ...
}

See demo module for working examples or some random commit to see how to apply this little lib.

TODO: add examples with logic extracted into plain classes.

Gradle

dependencies {
    compile 'pl.mg6.rxjava2.disposeondestroy:core:0.1.0'
    compile 'pl.mg6.rxjava2.disposeondestroy:support:0.1.0'
}

Versions

Version
0.1.0