Skip to content

Commit

Permalink
Merge pull request #40 from MetaCell/feature/39
Browse files Browse the repository at this point in the history
#39 extending and making serialisation generic
  • Loading branch information
zsinnema authored Jan 25, 2023
2 parents 0026a9c + 21208e8 commit 89955ae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/react-diagrams/MetaLinkModel.ts
Original file line number Diff line number Diff line change
@@ -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 = {}) {
Expand All @@ -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<string>) {
const additionalParams = Object.create({});
params.forEach(param => {
additionalParams[param] = this.getOption(param);
});
return {
...super.serialize(),
...additionalParams,
};
}
}
11 changes: 11 additions & 0 deletions src/react-diagrams/MetaNodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,15 @@ export class MetaNodeModel extends NodeModel {
getNodeBoundingBox(): BoundingBox {
return this.boundingBox;
}

serialise(params: Array<string>) {
const additionalParams = Object.create({});
params.forEach(param => {
additionalParams[param] = this.getOption(param);
});
return {
...super.serialize(),
...additionalParams,
};
}
}

0 comments on commit 89955ae

Please sign in to comment.