mirror of
https://gitee.com/antv/g6.git
synced 2024-12-03 04:08:32 +08:00
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
const deepMix = require('@antv/util/lib/deep-mix');
|
|
const each = require('@antv/util/lib/each');
|
|
const wrapBehavior = require('@antv/util/lib/event/wrap-behavior');
|
|
|
|
class PluginBase {
|
|
constructor(cfgs) {
|
|
this._cfgs = deepMix(this.getDefaultCfgs(), cfgs);
|
|
}
|
|
getDefaultCfgs() {
|
|
return {};
|
|
}
|
|
initPlugin(graph) {
|
|
const self = this;
|
|
self.set('graph', graph);
|
|
const events = self.getEvents();
|
|
const bindEvents = {};
|
|
each(events, (v, k) => {
|
|
const event = wrapBehavior(self, v);
|
|
bindEvents[k] = event;
|
|
graph.on(k, event);
|
|
});
|
|
this._events = bindEvents;
|
|
this.init();
|
|
}
|
|
init() {}
|
|
getEvents() {
|
|
return {};
|
|
}
|
|
get(key) {
|
|
return this._cfgs[key];
|
|
}
|
|
set(key, val) {
|
|
this._cfgs[key] = val;
|
|
}
|
|
destroy() {}
|
|
destroyPlugin() {
|
|
this.destroy();
|
|
const graph = this.get('graph');
|
|
const events = this._events;
|
|
each(events, (v, k) => {
|
|
graph.off(k, v);
|
|
});
|
|
this._events = null;
|
|
this._cfgs = null;
|
|
this.destroyed = true;
|
|
}
|
|
}
|
|
|
|
module.exports = PluginBase;
|