I am not sure if this is a good question or not but I would love to hear some inputs on this.
Imagine there are 2 kinds of events:
A: a mouse click
B: mouse is currently inside a box
Also, imagine there are 2 kinds of event handler functions:
f: console.log("mouse is clicked")
g: console.log("mouse is clicked inside the box")
Now what I want the code to do is, when the mouse is clicked anywhere but inside the box, display the message "mouse is clicked". However, when the mouse is clicked inside the box, display the message "mouse is clicked inside the box".
My current way of implementation looks like follows:
if (A) then {f()}
if (A and B) then {g()}
In short, I registered f as a listener for A, and created a new event that fires when both A and B hold, and registered g ans a listener for that event.
of course, when the mouse is clicked inside the box, I get two messages: "mouse is clicked inside the box" "mouse is clicked"
rather than the single "mouse is clicked inside the box" that I am looking for.
Is there any formal way of defining what is happening, and what is the best way to address it? In short, I want the event handler g to have precedence over the handler f, such that when g is invoked it suppresses the invocation of f.