package com.yidianling.ydlcommon.custom.mvp

import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

/**
 * author : Zhangwenchao
 * e-mail : zhangwch@yidianling.com
 * time   : 2018/01/29
 *
 * 用于 Rx
 */
abstract class RxPresenter<V: MVPView, out M: MVPModel>(view: V): BasePresenter<V, M>(view) {

    private val compositeDisposable: CompositeDisposable by lazy { CompositeDisposable() }

    override fun onViewDestroy() {
        super.onViewDestroy()
        clearDisposable()
    }

    fun addDisposable(d: Disposable) {
        compositeDisposable.add(d)
    }

    fun removeDisposable(d: Disposable) {
        compositeDisposable.remove(d)
    }

    private fun clearDisposable() {
        compositeDisposable.clear()
    }
}