refactor(types): use same structure for nodes and edges

This commit is contained in:
moklick
2024-02-17 15:45:10 +01:00
parent 776f6ce0b7
commit ad7403cc75
24 changed files with 176 additions and 147 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ const edgesSelector = (state: ReactFlowState) => state.edges;
* @public
* @returns An array of edges
*/
export function useEdges<EdgeData>(): Edge<EdgeData>[] {
const edges = useStore(edgesSelector, shallow);
export function useEdges<EdgeType extends Edge = Edge>(): EdgeType[] {
const edges = useStore(edgesSelector, shallow) as EdgeType[];
return edges;
}
+5 -3
View File
@@ -1,15 +1,17 @@
import { useEffect, useRef } from 'react';
import { useReactFlow } from './useReactFlow';
import type { OnInit, Node } from '../types';
import type { OnInit, Node, Edge } from '../types';
/**
* Hook for calling onInit handler.
*
* @internal
*/
export function useOnInitHandler<NodeType extends Node = Node>(onInit: OnInit<NodeType> | undefined) {
const rfInstance = useReactFlow<NodeType>();
export function useOnInitHandler<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
onInit: OnInit<NodeType, EdgeType> | undefined
) {
const rfInstance = useReactFlow<NodeType, EdgeType>();
const isInitialized = useRef<boolean>(false);
useEffect(() => {