Appendix B. The six plagues of event handling
We’ve identified six sources of bugs in the observer pattern. FRP banishes all of them. Here we’ll describe each problem in detail, with a short explanation of how FRP fixes it.
Let’s say you’re developing a program for drawing diagrams, in which graphical elements can be selected or deselected. The rules are these:
- If you click an item, it’s selected.
- If an item is selected and you click elsewhere, it gets deselected.
- When nothing is selected, you see a crosshair cursor.
- When any element is selected, the cursor is an arrow.
Figure B.1 shows three steps performed with the diagram program:
1. At first nothing is selected, and you’re ready to click the triangle.
2. When you’ve clicked the triangle, it’s highlighted, and you see an arrow cursor.
3. You get ready to click the octagon.
- Deselecting the triangle.
- Selecting the octagon.
The following listing shows the code to set the shape of the cursor depending on how many items are selected.