Skip to content

Commit

Permalink
fix: add a symbol to distinguish plugin registration method
Browse files Browse the repository at this point in the history
  • Loading branch information
wumail authored and boyongjiong committed Aug 11, 2023
1 parent 4e9a90e commit 1e0a40a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/core/src/LogicFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import { snaplineTool } from './tool/SnaplineTool';
import { EditConfigInterface } from './model/EditConfigModel';
import { Theme } from './constant/DefaultTheme';
import { ElementType, EventType } from './constant/constant';
import { createUuid } from './util';

if (process.env.NODE_ENV === 'development') {
require('preact/debug');// eslint-disable-line global-require
}

const pluginFlag = Symbol('plugin register by Logicflow.use');
type ExtensionMapValueType = { extension: Extension, props?: any, [pluginFlag]: symbol};

type GraphConfigModel = {
nodes: _Model.BaseNodeModel[];
edges: _Model.BaseEdgeModel[];
Expand Down Expand Up @@ -86,7 +88,7 @@ export default class LogicFlow {
/**
* 全局配置的插件,所有的LogicFlow示例都会使用
*/
static extensions: Map<string, { extension: Extension, props?: any }> = new Map();
static extensions: Map<string, ExtensionMapValueType> = new Map();
/**
* 插件扩展方法
* @example
Expand Down Expand Up @@ -979,6 +981,7 @@ export default class LogicFlow {
preExtension && preExtension.destroy && preExtension.destroy();
this.extensions.set(pluginName,
{
[pluginFlag]: pluginFlag,
extension,
props,
});
Expand All @@ -995,7 +998,15 @@ export default class LogicFlow {
private installPlugins(disabledPlugins = []) {
// 安装插件,优先使用个性插件
const extensions = this.plugins ?? LogicFlow.extensions;
extensions.forEach(({ extension, props }: any) => {
extensions.forEach((ext: any) => {
let extension = null;
let props = null;
if (ext[pluginFlag]) {
extension = ext.extension;
props = ext.props;
} else {
extension = ext;
}
const pluginName = extension.pluginName || extension.name;
if (disabledPlugins.indexOf(pluginName) === -1) {
this.installPlugin(extension, props);
Expand Down

0 comments on commit 1e0a40a

Please sign in to comment.