Adds onAttach event.

This still needs a lot of work.

– The build system needs to be updated
– Tests need to be added
– The code might need a once-over

=====

This adds `onAttach`. Ref #1856 for more.