package com.cooleshow.base.rx

import com.cooleshow.base.rx.BaseException
import com.cooleshow.base.presenter.view.BaseView
import io.reactivex.rxjava3.core.Observer
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.subscribers.DefaultSubscriber

/*
    Rx订阅者默认实现
 */
//open class BaseSubscriber<T>(val baseView:BaseView): DefaultSubscriber<T>() {
//
//    override fun onNext(t: T) {
//    }
//
//    override fun onError(e: Throwable?) {
//        baseView.hideLoading()
//        if (e is BaseException){
//            baseView.onError(e.msg)
//        }
//    }
//
//    override fun onComplete() {
//        baseView.hideLoading()
//    }
//}

open class BaseSubscriber<T>(val baseView:BaseView): Observer<T> {

    override fun onNext(t: T) {
    }

    override fun onError(e: Throwable?) {
        baseView.hideLoading()
        if (e is BaseException){
            baseView.onError(e)
        }
    }

    override fun onComplete() {
        baseView.hideLoading()
    }

    override fun onSubscribe(d: Disposable) {
    }
}