mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-01 02:41:42 +00:00
Add slider debounce (#1479)
Sliders for exposure and brightness would spam messages on the backend. This used to cause crashes and can cause it to get quite laggy / delayed. This will add a 20ms debounce which won't send the value to the backend until the value hasn't changed for 20ms. --------- Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -25,9 +25,22 @@ const emit = defineEmits<{
|
||||
(e: "input", value: number): void;
|
||||
}>();
|
||||
|
||||
// Debounce function
|
||||
function debounce(func: (...args: any[]) => void, wait: number) {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
return function (...args: any[]) {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => func.apply(this, args), wait);
|
||||
};
|
||||
}
|
||||
|
||||
const debouncedEmit = debounce((v: number) => {
|
||||
emit("input", v);
|
||||
}, 20);
|
||||
|
||||
const localValue = computed({
|
||||
get: () => props.value,
|
||||
set: (v) => emit("input", parseFloat(v as unknown as string))
|
||||
set: (v) => debouncedEmit(parseFloat(v as unknown as string))
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user