chore(plugin): modify plugin methods

This commit is contained in:
yilin.qyl 2019-03-29 10:30:13 +08:00
parent d505e4a0f8
commit bdd782cd40
6 changed files with 9 additions and 9 deletions

View File

@ -9,7 +9,7 @@ class PluginBase {
getDefaultCfg() {
return {};
}
_init(graph) {
initPlugin(graph) {
const self = this;
self.set('graph', graph);
const events = self.getEvents();
@ -32,7 +32,9 @@ class PluginBase {
set(key, val) {
this._cfgs[key] = val;
}
destroy() {
destroy() {}
destroyPlugin() {
this.destroy();
const graph = this.get('graph');
const events = this._events;
each(events, (v, k) => {

View File

@ -48,7 +48,6 @@ class Grid extends Base {
destroy() {
const graphContainer = this.get('graph').get('container');
graphContainer.removeChild(this.get('container'));
super.destroy();
}
}

View File

@ -286,7 +286,6 @@ class Minimap extends Base {
const container = this.get('canvas');
this.get('canvas').destroy();
container.innerHTML = '';
super.destroy();
}
}

View File

@ -224,8 +224,8 @@ class Graph extends EventEmitter {
_initPlugins() {
const self = this;
Util.each(self.get('plugins'), plugin => {
if (!plugin.destroyed && plugin._init) {
plugin._init(self);
if (!plugin.destroyed && plugin.initPlugin) {
plugin.initPlugin(self);
}
});
}
@ -926,7 +926,7 @@ class Graph extends EventEmitter {
destroy() {
this.clear();
Util.each(this.get('plugins'), plugin => {
plugin.destroy();
plugin.destroyPlugin();
});
this.get('eventController').destroy();
this.get('itemController').destroy();

View File

@ -548,7 +548,7 @@ describe('all node link center', () => {
expect(graph.get('plugins').length).to.equal(1);
graph.emit('event');
expect(count).to.equal(1);
plugin.destroy();
plugin.destroyPlugin();
graph.emit('event');
expect(count).to.equal(1);
});

View File

@ -49,7 +49,7 @@ describe('minimap', () => {
expect(viewport.style.top).to.equal('20px');
expect(viewport.style.width).to.equal('160px');
expect(viewport.style.height).to.equal('160px');
minimap.destroy();
minimap.destroyPlugin();
const container = div.childNodes[1];
expect(container.innerHTML).to.equal('');
graph.zoom(2.5, { x: 250, y: 250 });