export default class PluginService {
constructor() {
- this._init = [];
+ this._init = undefined;
}
/**
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;
}
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']);
+ });
});
});