mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-02-20 01:31:20 +01:00
Do not notify plugins after their uninstall function has been called (#12098)
Fixes #12032
This commit is contained in:
@@ -19,7 +19,7 @@ import {callback as callCallback, isNullOrUndef, valueOrDefault} from '../helper
|
||||
|
||||
export default class PluginService {
|
||||
constructor() {
|
||||
this._init = [];
|
||||
this._init = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,12 +38,17 @@ export default class PluginService {
|
||||
this._notify(this._init, chart, 'install');
|
||||
}
|
||||
|
||||
if (this._init === undefined) { // Do not trigger events before install
|
||||
return;
|
||||
}
|
||||
|
||||
const descriptors = filter ? this._descriptors(chart).filter(filter) : this._descriptors(chart);
|
||||
const result = this._notify(descriptors, chart, hook, args);
|
||||
|
||||
if (hook === 'afterDestroy') {
|
||||
this._notify(descriptors, chart, 'stop');
|
||||
this._notify(this._init, chart, 'uninstall');
|
||||
this._init = undefined; // Do not trigger events after uninstall
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -480,5 +480,31 @@ describe('Chart.plugins', function() {
|
||||
await jasmine.triggerMouseEvent(chart, 'pointerleave', {x: 0, y: 0});
|
||||
expect(results).toEqual(['beforetest', 'aftertest', 'beforemouseout', 'aftermouseout']);
|
||||
});
|
||||
|
||||
it('should not call plugins after uninstall', async function() {
|
||||
const results = [];
|
||||
const chart = window.acquireChart({
|
||||
options: {
|
||||
events: ['test'],
|
||||
plugins: {
|
||||
testPlugin: {
|
||||
events: ['test']
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: [{
|
||||
id: 'testPlugin',
|
||||
reset: () => results.push('reset'),
|
||||
afterDestroy: () => results.push('afterDestroy'),
|
||||
uninstall: () => results.push('uninstall'),
|
||||
}]
|
||||
});
|
||||
chart.reset();
|
||||
expect(results).toEqual(['reset']);
|
||||
chart.destroy();
|
||||
expect(results).toEqual(['reset', 'afterDestroy', 'uninstall']);
|
||||
chart.reset();
|
||||
expect(results).toEqual(['reset', 'afterDestroy', 'uninstall']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user