refactor: tidy composables

This commit is contained in:
三咲智子 2023-01-07 02:40:15 +08:00
parent bf8070c4b9
commit e0741d58a9
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
14 changed files with 177 additions and 175 deletions

View file

@ -1,30 +0,0 @@
import type { ComponentInternalInstance } from 'vue'
import { onActivated, onDeactivated, ref } from 'vue'
/**
* ### Whether the current component is running in the background
*
* for handling problems caused by the keepalive function
*/
export function useDeactivated() {
const deactivated = ref(false)
onActivated(() => deactivated.value = false)
onDeactivated(() => deactivated.value = true)
return deactivated
}
/**
* ### When the component is restored from the background
*
* for handling problems caused by the keepalive function
*/
export function onReactivated(hook: Function, target?: ComponentInternalInstance | null): void {
const initial = ref(true)
onActivated(() => {
if (initial.value)
return
hook()
}, target)
onDeactivated(() => initial.value = false)
}