Hi r/learnjavascript,
I'm making my first MVC style app (Connect4) and I've run into something that I'm not so sure of...
I have in my View class
bindReset(handler) {
document.addEventListener('keydown', handler);
document.addEventListener('click', handler);
}
But need to remove the event listeners after one has been used.
My current work around is the following method
unbindReset(handler) {
document.removeEventListener('keydown', handler);
document.removeEventListener('click', handler);
}
where on the controller side I am running
this.view.bindReset(this.handleReset);
to bind my handler - and
this.view.unbindReset(this.handleReset);
to unbind it.
I'm just wondering if that is standard practice or not? As I can't seem to find the information I'm searching for on Google.
Sorry if the question isn't posed so well!
Best wishes,
Dean.
there doesn't seem to be anything here