refactor: make nodes/edges for useStates helpers optional

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent a9e7eb31ea
commit 35165c3a98
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -61,7 +61,7 @@ const updateEdge = (edge: GraphEdge, newConnection: Connection, edges: GraphEdge
export const applyEdgeChanges = (changes: EdgeChange[], edges: GraphEdge[]) => applyChanges(changes, edges)
export const applyNodeChanges = (changes: NodeChange[], nodes: GraphNode[]) => applyChanges(changes, nodes)
export const useEdgesState = ({ edges, options }: UseEdgesStateOptions): UseEdgesState => {
export const useEdgesState = ({ edges, options }: UseEdgesStateOptions = {}): UseEdgesState => {
const { store } = useVueFlow(options)
if (edges && edges.length) store.setEdges(edges)
return {
@@ -93,7 +93,7 @@ export const useEdgesState = ({ edges, options }: UseEdgesStateOptions): UseEdge
}
}
export const useNodesState = ({ nodes, options }: UseNodesStateOptions): UseNodesState => {
export const useNodesState = ({ nodes, options }: UseNodesStateOptions = {}): UseNodesState => {
const { store } = useVueFlow(options)
if (nodes && nodes.length) store.setNodes(nodes)
return {
+2 -2
View File
@@ -124,7 +124,7 @@ export interface FlowProps<N = any, E = N> {
export type FlowOptions<N = any, E = N> = FlowProps<N, E>
export interface UseNodesStateOptions<Data = any> {
nodes: Node<Data>[]
nodes?: Node<Data>[]
options?: Pick<
FlowOptions<Data, any>,
| 'applyDefault'
@@ -141,7 +141,7 @@ export interface UseNodesStateOptions<Data = any> {
>
}
export interface UseEdgesStateOptions<Data = any> {
edges: Edge<Data>[]
edges?: Edge<Data>[]
options?: Pick<
FlowOptions<any, Data>,
| 'applyDefault'