fix(cardassignment): debounce w/ immediate start
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user