DEV Community

Discussion on: When Event Listeners Won't Listen

Collapse
 
neradev profile image
Moritz Schramm

Has there been a reason, why you decided for adding and removing event listeners (which causes a lot of overhead) vs. you do some state management and keep both listerns which are added once and check whether the state is corresponding to one or the other?

Collapse
 
aryaziai profile image
aryaziai

Hey, thank you for the comment. I just started Javascript so I haven't gotten to state yet.

Collapse
 
jamesthomson profile image
James Thomson

This is what I was thinking while reading this as well. Rather than manage event listeners, manage the current state. Much simpler (and modular) to switch around the paintbrush type and call the associated function(s).

Collapse
 
ionline247 profile image
Matthew Bramer • Edited

Maintaining state would be the preferred approach. He could even use a pub/sub <gasp/> event listener and toggle state that way