import type { UnknownPlugin, Uppy } from '@uppy/core'
import { shallowEqualObjects } from 'shallow-equal'
import { onBeforeUnmount, onMounted, type Ref, watch } from 'vue'
export default function useUppy
>(
installPlugin: () => void,
plugin: Ref
,
uppy: Uppy,
props: Ref | undefined>,
): void {
onMounted(() => {
installPlugin()
})
onBeforeUnmount(() => {
uppy.removePlugin(plugin.value!)
})
watch(
() => props.value,
(current, old) => {
if (!shallowEqualObjects(current, old)) {
plugin.value!.setOptions({ ...current })
}
},
)
}