WIP jordan
This commit is contained in:
18
app/utils/refDebounced.ts
Normal file
18
app/utils/refDebounced.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ref, watch, type Ref } from 'vue'
|
||||
|
||||
/** Debounced mirror of a ref (no @vueuse dependency). */
|
||||
export function refDebounced<T>(source: Ref<T>, ms: number): Ref<T> {
|
||||
const debounced = ref(source.value) as Ref<T>
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
watch(
|
||||
source,
|
||||
(v) => {
|
||||
if (timer) clearTimeout(timer)
|
||||
timer = setTimeout(() => {
|
||||
debounced.value = v
|
||||
}, ms)
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
return debounced
|
||||
}
|
||||
Reference in New Issue
Block a user