Cancel previous timeout
continuous-integration/drone/push Build is passing Details

main
Clément FRÉVILLE 1 year ago
parent b5ec58b936
commit 90400a09ea

@ -8,6 +8,9 @@ const display = /** @type {HTMLDivElement} */ (document.getElementById('display'
const light = /** @type {HTMLDivElement} */ (document.getElementById('light')); const light = /** @type {HTMLDivElement} */ (document.getElementById('light'));
const keypad = /** @type {HTMLDivElement} */ (document.getElementById('keypad')); const keypad = /** @type {HTMLDivElement} */ (document.getElementById('keypad'));
/** @type {number|null} */
let taskId = null;
/** /**
* @param {number} len * @param {number} len
* @returns {string} * @returns {string}
@ -30,6 +33,10 @@ function resetCode() {
* @param {number} digit * @param {number} digit
*/ */
function composeDigit(digit) { function composeDigit(digit) {
if (taskId !== null) {
clearTimeout(taskId);
taskId = null;
}
builder += digit.toString(); builder += digit.toString();
display.innerText = builder + '_'.repeat(CODE.length - builder.length); display.innerText = builder + '_'.repeat(CODE.length - builder.length);
light.classList.remove(IS_SUCCESS, IS_ERROR); light.classList.remove(IS_SUCCESS, IS_ERROR);
@ -37,7 +44,7 @@ function composeDigit(digit) {
light.classList.add(IS_SUCCESS); light.classList.add(IS_SUCCESS);
} else { } else {
light.classList.add(IS_ERROR); light.classList.add(IS_ERROR);
setTimeout(resetCode, DELAY); taskId = setTimeout(resetCode, DELAY);
} }
} }

Loading…
Cancel
Save