diff --git a/src/react-diagrams/MetaLinkModel.ts b/src/react-diagrams/MetaLinkModel.ts index 86b9a9f..097f49f 100644 --- a/src/react-diagrams/MetaLinkModel.ts +++ b/src/react-diagrams/MetaLinkModel.ts @@ -1,5 +1,5 @@ import { DefaultLinkModel } from '@projectstorm/react-diagrams'; -import { ReactDiagramMetaTypes } from '../constants'; +import { ReactDiagramMetaTypes, CallbackTypes } from '../constants'; export class MetaLinkModel extends DefaultLinkModel { constructor(options = {}) { @@ -8,4 +8,35 @@ export class MetaLinkModel extends DefaultLinkModel { type: ReactDiagramMetaTypes.META_LINK, }); } + + setOption(label: string, newValue: any, triggerUpdate?: boolean | undefined) { + // @ts-ignore + this.options[label] = newValue; + if (triggerUpdate) { + this.flagUpdate(CallbackTypes.OPTIONS_UPDATED); + } + } + + getOption(label: string): any { + // @ts-ignore + return this.getOptions()[label]; + } + + flagUpdate(updateType: CallbackTypes, extraCondition?: CallbackTypes) { + this.fireEvent( + { node: this, function: updateType, extraCondition: extraCondition }, + updateType + ); + } + + serialise(params: Array) { + const additionalParams = Object.create({}); + params.forEach(param => { + additionalParams[param] = this.getOption(param); + }); + return { + ...super.serialize(), + ...additionalParams, + }; + } } diff --git a/src/react-diagrams/MetaNodeModel.ts b/src/react-diagrams/MetaNodeModel.ts index 497f863..f79c141 100644 --- a/src/react-diagrams/MetaNodeModel.ts +++ b/src/react-diagrams/MetaNodeModel.ts @@ -125,4 +125,15 @@ export class MetaNodeModel extends NodeModel { getNodeBoundingBox(): BoundingBox { return this.boundingBox; } + + serialise(params: Array) { + const additionalParams = Object.create({}); + params.forEach(param => { + additionalParams[param] = this.getOption(param); + }); + return { + ...super.serialize(), + ...additionalParams, + }; + } }