refactor(core): omit internal properties when using toObject

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-02-22 20:20:11 +01:00
committed by Braks
parent c8325ecf37
commit 10f50740b6
2 changed files with 24 additions and 4 deletions
+22 -2
View File
@@ -567,8 +567,28 @@ export function useActions(state: State, getters: ComputedGetters): Actions {
// we have to stringify/parse so objects containing refs (like nodes and edges) can potentially be saved in a storage
return JSON.parse(
JSON.stringify({
nodes: state.nodes,
edges: state.edges,
nodes: state.nodes.map((n) => {
// omit internal properties when exporting
const {
computedPosition: _,
handleBounds: __,
selected: ___,
dimensions: ____,
isParent: _____,
resizing: ______,
dragging: _______,
initialized: ________,
...rest
} = n
return rest
}),
edges: state.edges.map((e) => {
// omit internal properties when exporting
const { selected: _, sourceNode: __, targetNode: ___, ...rest } = e
return rest
}),
position: [state.viewport.x, state.viewport.y],
zoom: state.viewport.zoom,
} as FlowExportObject),
+2 -2
View File
@@ -97,8 +97,8 @@ export enum SelectionMode {
}
export interface FlowExportObject {
nodes: GraphNode[]
edges: GraphEdge[]
nodes: Node[]
edges: Edge[]
position: [number, number]
zoom: number
}