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?
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).
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?
Hey, thank you for the comment. I just started Javascript so I haven't gotten to state yet.
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).
Maintaining state would be the preferred approach. He could even use a pub/sub <gasp/> event listener and toggle state that way