Adds onAttach event.

This still needs ~~a lot of~~ some work.

– ~~The build system needs to be updated~~ (no it doesn't)
– ~~Tests need to be added~~
– The code needs cleaned up. I did it pretty fast
– Docs

=====

This adds `onAttach`. Ref #1856 for more about why this event is important.
We should talk about if we want this to be a new public method.