package com.all.pdfreader.pro.app.viewmodel

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import com.all.pdfreader.pro.app.model.FileActionEvent

/**
 * 公用观察FileActionEvent事件函数，只观察需要观察的响应
 */
inline fun <reified T : FileActionEvent> LiveData<FileActionEvent>.observeEvent(
    owner: LifecycleOwner,
    crossinline handler: (T) -> Unit
) {
    this.observe(owner) { event ->
        if (event is T) {
            handler(event)
        }
    }
}