feat(store, flow)!: Add useNode/useEdge-state helpers

* for two way binding use the helpers
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent 81c8145f3a
commit c80ab8fe50
5 changed files with 21 additions and 11 deletions
+9 -8
View File
@@ -281,18 +281,19 @@ export const getConnectedEdges = (nodes: GraphNode[], edges: GraphEdge[]) => {
return edges.filter((edge) => nodeIds.includes(edge.source) || nodeIds.includes(edge.target))
}
export const onLoadGetNodes = (currentStore: FlowStore) => (): GraphNode[] => currentStore.nodes
export const onLoadGetEdges = (currentStore: FlowStore) => (): GraphEdge[] => currentStore.edges
export const onLoadGetElements = (currentStore: FlowStore) => (): FlowElements => [...currentStore.nodes, ...currentStore.edges]
export const onLoadGetNodes = (store: FlowStore) => (): GraphNode[] => store.nodes
export const onLoadGetEdges = (store: FlowStore) => (): GraphEdge[] => store.edges
export const onLoadGetElements = (store: FlowStore) => (): FlowElements => [...store.nodes, ...store.edges]
export const onLoadToObject = (currentStore: FlowState) => (): FlowExportObject => {
export const onLoadToObject = (store: FlowState) => (): FlowExportObject => {
// 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({
elements: currentStore.elements,
position: [currentStore.transform[0], currentStore.transform[1]],
zoom: currentStore.transform[2],
}),
nodes: store.nodes,
edges: store.edges,
position: [store.transform[0], store.transform[1]],
zoom: store.transform[2],
} as FlowExportObject),
)
}