I got problem with removing eventListener form function.
Every call a function is adding another event and after that is not removed.
Im checking in console with:
getEventListeners(document.querySelector('body'));
function handleKeyDown(e) {
const workoutEdit = document.querySelector('.formEdit');
const backdrop = document.querySelector('.backdrop');
if (e.key === 'Escape' && workoutEdit && backdrop) {
curWorkout.parentElement.removeChild(workoutEdit);
curWorkout.parentElement.removeChild(backdrop);
body.removeEventListener('keydown', handleKeyDown);
}
if (e.key === 'Enter') {
this.#workouts[indexWorkout].distance = +editDistance.value;
this.#workouts[indexWorkout].duration = +editDuration.value;
console.log(this.#workouts);
body.removeEventListener('keydown', handleKeyDown);
}
}
body.addEventListener('keydown', handleKeyDown.bind(this));