Implement document.register lifecycle callbacks

This depends on #198