Suggesting using addEventListener once option in docs

Adding `{once : true}` to `node.addEventListener` causes the event trigger to be removed after first use. This built-in method cleans up the requirement to remove event within event handler.
This commit is contained in:
Thomas Reese 2020-08-27 18:39:34 -07:00 committed by GitHub
parent 4e4dfb6af5
commit e22d9c8689
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,14 +37,12 @@ const animateCSS = (element, animation, prefix = 'animate__') =>
node.classList.add(`${prefix}animated`, animationName);
// When the animation ends, we clean the classes and resolve the Promise
function handleAnimationEnd() {
handleAnimationEnd = () => {
node.classList.remove(`${prefix}animated`, animationName);
node.removeEventListener('animationend', handleAnimationEnd);
resolve('Animation ended');
}
node.addEventListener('animationend', handleAnimationEnd);
node.addEventListener('animationend', handleAnimationEnd, {once : true});
});
```