@tokens-studio/graph-engine
Version:
An execution engine to handle Token Studios generators and resolvers
45 lines • 1.31 kB
JavaScript
import { makeObservable, observable } from 'mobx';
import { v4 as uuid } from 'uuid';
export class Edge {
annotations = {};
id;
source;
sourceHandle;
target;
targetHandle;
constructor(props) {
this.id = props.id || uuid();
this.source = props.source;
this.sourceHandle = props.sourceHandle;
this.target = props.target;
this.targetHandle = props.targetHandle;
this.annotations = props.annotations || {};
makeObservable(this, {
annotations: observable.shallow
});
}
serialize() {
const serialized = {
id: this.id,
source: this.source,
sourceHandle: this.sourceHandle,
target: this.target,
targetHandle: this.targetHandle
};
if (Object.keys(this.annotations).length > 0) {
serialized.annotations = this.annotations;
}
return serialized;
}
static deserialize(props) {
return new Edge({
id: props.id,
source: props.source,
sourceHandle: props.sourceHandle,
target: props.target,
targetHandle: props.targetHandle,
annotations: props.annotations || {}
});
}
}
//# sourceMappingURL=edge.js.map