How am I able to manually remove/undo a wrap on a Highcharts Class Prototype?
I currently have this in a class in Angular and it seems like the wrap is holding onto my method as a closure even after the component is destroyed.
import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnDestroy
constructor() {
function logRefresh(H) {
H.wrap(H.Tooltip.prototype, 'refresh', function(proceed, point) {
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
console.log(proceed, point);
});
}
logRefresh(Highcharts);
}
ngOnDestroy(): void {
...
}
}
The wrap method overwrites an original function in Highcharts prototype, so it is a permanent change. You can check how the method exactly works here.
As a solution, you can store an original function somewhere, for example:
H.wrap(H.Tooltip.prototype, 'refresh', function(proceed) {
console.log('refresh');
if (!H.Tooltip.prototype.refreshOriginal) {
H.Tooltip.prototype.refreshOriginal = proceed;
}
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
And restore it when you want.
const tooltipProto = H.Tooltip.prototype;
// restore original refresh function
tooltipProto.refresh = tooltipProto.refreshOriginal;
delete tooltipProto.refreshOriginal;
Live demo: http://jsfiddle.net/BlackLabel/nfqcwhk6/
Docs: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts