In a custom datasource plugin, how to react on panel events?

I’m writing a datasource plugin, and I have to be able to close connections to the backend.
For instance, in a graph panel’s query editor, when the user clicks on the “delete” icon, my plugin has
to close the connection to the backend.

Being new to typescript/react/angular development, I’d like to know wether this is even possible given Grafana’s current implementation.