KayCee
07/28/2020, 10:20 AMtypealias CompletionBlock<T> = UseCase.RequestBlock<T>.() -> Unit
RequestBlock<T> class is like this:
class RequestBlock<T> {
private var onSuccess: ((T) -> Unit)? = null
private var onFail: ((ErrorModel, CallableImp) -> Unit)? = null
private var onFinally: (() -> Unit)? = null
fun onSuccess(block: (T) -> Unit) {
onSuccess = block
}
fun onFail(block: (ErrorModel, CallableImp) -> Unit) {
onFail = block
}
fun onFinally(block: () -> Unit) {
onFinally = block
}
operator fun invoke(result: T) {
onSuccess?.invoke(result)
}
operator fun invoke(error: ErrorModel, apiCallable: CallableImp) {
onFail?.invoke(error, apiCallable)
}
operator fun invoke() {
onFinally?.invoke()
}
}
okarm
07/28/2020, 10:42 AM