Chapter 8. Listening to notifications
This chapter covers
- Setting up event handlers on your build
- Setting up application event handlers
- Adding listeners to model updates
- Transforming any class into an event publisher
Think for a moment how your typical work day starts. You get up on time (most likely) because your alarm clock rings. You grab some warm toast for breakfast because you hear it popped from the toaster. On your way to work, you know to stop on the street because the traffic light changes to red.
What is common to all these cases is that you take action as a response to some stimulus, whether auditory (your alarm clock ringing) or visual (the traffic light). It’s as if you’re reacting to signals sent by different agents. Could you imagine your morning routine without all those signals? It could turn out to be a bit chaotic. It might also be tedious, because you’d constantly have to check for a particular condition to see if you could proceed. Sometimes it’s better to react to a signal rather than poll for it.
The same principle applies to applications. You know that during a build, a predefined set of steps must take place. After all, the build must be reproducible every time. But a build should also be extensible: not every shoe fits every foot. Sometimes you’ll need to tweak the build. Signals, or events as we’ll call them from now on, are a perfect fit to make this happen.