I am creating a multimodal editor using reactive-banana - and for the most part it is perfect. To expand my script, the editor is some kind of mapping software, or you might think of it as a very simple graphical editor. Currently, it has two states - selection mode and polygon creation mode. In the selection mode, the user can select previously created polygons with the right mouse button (which theoretically leads you to the new selected mode), or they can start creating a new polygon with the left mouse button.
The intention is that when you click the left mouse button, we switch from selection mode to polygon creation mode. In this mode, the left mouse button means βadd a new vertexβ until the user returns to the original vertex. At this point, they closed the polygon, so back to the selection mode.
I implemented this in several different ways, and recently noticed that the event switcher almost makes it very elegant. I can:
defaultMode :: Frameworks t => HadoomGUI -> Moment t (Behavior t Diagram) defaultMode gui@HadoomGUI {..} = do mouseMoved <- registerMotionNotify guiMap mouseClicked <- registerMouseClicked guiMap let lmbClicked = ... gridCoords = ... diagram = ... switchToCreateSector <- execute ((\m -> FrameworksMoment (=<< trimB =<< createSectorMode gui emptySectorBuilder m)) <$> (gridCoords <@ lmbClicked)) return (switchB diagram switchToCreateSector)
As well as
createSectorMode :: Frameworks t => HadoomGUI -> SectorBuilder -> Point V2 Double -> Moment t (Behavior t Diagram) createSectorMode HadoomGUI{..} initialSectorBuilder firstVertex = do mouseClicked <- registerMouseClicked guiMap ...
It certainly works - for a single click. If I click on the map once, I will switch to the sector creation mode from the state I was in. However, if I click again, defaultMode will receive a click event and switch to the new polygon creation mode, discarding the previous state.
What I would like to do is enable defaultMode once and never be able to return. Essentially, I want to "swap" the Behavior t Diagram created by defaultMode result of createSectorMode .
I understand that reactive-banana has problems building dynamic events, but I am ready to live with it at the moment. The above wording is much more accurate than everything I have written so far - for example, having a single CurrentState variable and filtering various events based on its contents. The problem I am facing is that it is too big and I have too many opportunities for me to ruin everything. With switching, I mean only those events that I can talk about.