import { GraphConnection , GraphEdge } from '@src/modules/shared/SharedTypes' ; import produce , { castDraft } from 'immer' ; export const addEdgeToConnection = < T , Conn extends GraphConnection < T > , Edge extends GraphEdge < T > > ( connection , edge ) => { const newConnection = produce ( connection , ( draft ) => { const newEdge = castDraft ( edge ) ; if ( draft . edges ) { draft . edges . unshift ( newEdge ) ; } else { draft . edges = [ newEdge ] ; } } ) ; return newConnection ; } ;