import Node from '@/components/node/node' ; import Port from '@/components/port/port' ; import { dataMutationBoundary } from './helper' ; import store from '@/store' ; import { OutputPort } from '@/components/port' ; /**
 * Traverses the downflow of the starting node.
 * Stores the post-traversal order in "order".
 */ const traverse = ( node , visited , order ) => { if ( visited . has ( node ) ) { return ; } visited . add ( node ) ; for ( const to of node . getOutputNodes ( ) ) { traverse ( to , visited , order ) ; } order . push ( node ) ; } ; /**
 * Obtain a topological order of the diagram.
 */ export const topologicalOrder = ( nodes ) : Node [ ] => { const visited = new Set < Node > ( ) ; const order = [ ] ; for ( const node of nodes ) { traverse ( node , visited , order ) ; } order . reverse ( ) ; return order ; } ; const propagate = ( nodes ) => { const order = topologicalOrder ( nodes ) ; for ( const node of order ) { node . startUpdate ( ) ; } for ( const node of order ) { node . clearUpdatedPorts ( ) ; } if ( store . state . systemOptions . dataMutationBoundaryVisible ) { dataMutationBoundary ( true ) ; } } ; export const propagatePort = ( port ) => { propagate ( port . getConnectedNodes ( ) ) ; if ( ! port . isInput ) { ( port as OutputPort ) . clearPackageUpdate ( ) ; } } ; export const propagateNode = ( node ) => { propagate ( [ node ] ) ; } ; export const propagateNodes = ( nodes ) => { propagate ( nodes ) ; } ;