Created
September 18, 2018 06:58
-
-
Save markchristopherng/56e58ea3cc91ddac3bcd42fa94a60b12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class BaseViewModel : ViewModel() { | |
private val disposableList = mutableListOf<Disposable>() | |
// integration with rx | |
fun <T> Observable<T>.subscribe(stateLiveData: StateLiveData<T>, successOnFirstValue: Boolean = true) = stateLiveData.post(this, successOnFirstValue).also { disposableList.add(it) } | |
override fun onCleared() { | |
disposableList.filter { !it.isDisposed }.forEach { it.dispose() } | |
disposableList.clear() | |
super.onCleared() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment