Watching the events flow by
The APIs we have seen in the previous chapters allow you to create observables and react to the changes via reactions. MobX also gives you a way to tap into the events that flow internally to make the reactive system work. By attaching listeners to these events, you can fine-tune the use of some expensive resources or control which updates are allowed to be applied to the observables.
Hooking into the observability
Normally, reactions are the place where we read observables and apply some side effects. This tells MobX to start tracking the observable and re-trigger the reaction on changes. However, if we look at this from the perspective of the observable, how does it know when it is being used by a reaction? How can it do a one-time setup when it is read in a reaction and also clean up when it's no longer being used?
What we need here is the ability to know when an observable becomes observed and when it becomes unobserved: the two points in time where it becomes...