fix(cardassignment): debounce w/ immediate start

This commit is contained in:
2025-04-22 22:25:54 +02:00
parent 1605b0f7b2
commit 1d6ed99073
3 changed files with 28 additions and 16 deletions

View File

@@ -4,8 +4,8 @@
Html5QrcodeScanner,
Html5QrcodeScanType,
Html5QrcodeSupportedFormats,
Html5QrcodeScannerState,
} from "html5-qrcode";
import { debounce } from "underscore";
export let width;
export let height;
@@ -13,23 +13,17 @@
const dispatch = createEventDispatcher();
const debounceFunc = (func, delay) => {
let timer;
return function (...args) {
const context = this;
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(context, args);
}, delay);
};
};
const debouncedDispatch = debounceFunc(function (decodedText) {
console.log("dispatchEvent");
dispatch("detect", { decodedText });
}, 500);
const debouncedDispatch = debounce(
function (decodedText) {
// console.log("dispatchEvent");
dispatch("detect", { decodedText });
},
500,
true
);
function onScanSuccess(decodedText, decodedResult) {
// console.log("onScanSuccess", decodedText);
if (!paused) {
debouncedDispatch(decodedText);
}