From 10394a8e50288be4967228c5d6178670e5187c4b Mon Sep 17 00:00:00 2001 From: Silviu Alexandru Avram Date: Tue, 13 Aug 2019 10:21:24 +0200 Subject: [PATCH] chore(set-a11y-status): use debounce for a11y message cleanup (#742) --- src/set-a11y-status.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/set-a11y-status.js b/src/set-a11y-status.js index 12b14e656..06869a9a7 100644 --- a/src/set-a11y-status.js +++ b/src/set-a11y-status.js @@ -1,10 +1,14 @@ +import {debounce} from './utils' + // istanbul ignore next let statusDiv = typeof document === 'undefined' ? null : document.getElementById('a11y-status-message') -let cleanupTimerID +const cleanupStatus = debounce(() => { + getStatusDiv().textContent = '' +}, 500) /** * @param {String} status the status message @@ -14,17 +18,9 @@ function setStatus(status) { if (!status) { return } - if (cleanupTimerID) { - clearTimeout(cleanupTimerID) - cleanupTimerID = null - } div.textContent = status - - cleanupTimerID = setTimeout(() => { - div.textContent = '' - cleanupTimerID = null - }, 500) + cleanupStatus() } /**