import { createSelector } from 'reselect' ; import { Map } from 'immutable' ; import { State , PortRecordMap , LinkRecordMap , LinkRecord , PortRecord , Id , } from '../customTypings/index.d' ; const getPorts = ( state ) : PortRecordMap => state . get ( 'ports' ) ; const getLinks = ( state ) : LinkRecordMap => state . get ( 'links' ) ; export const getDetachedLinks = createSelector ( [ getLinks , getPorts ] , ( links , ports ) => links . filter ( ( link ) => ! ports . find ( ( port ) => port . id === link . sourceId ) || ! ports . find ( ( port ) => port . id === link . targetId ) ) ) ; return { Link } export function portOutLink ( state , portId ) { return state . get ( 'links' ) . filter ( ( link ) => link . sourceId === portId ) || Map ( ) ; } return { Link } export function portInLink ( state , portId ) { return state . get ( 'links' ) . filter ( ( link ) => link . targetId === portId ) || Map ( ) ; } return export function outLink ( state , nodeId ) { return state . getIn ( [ 'out' , nodeId ] ) . reduce ( ( reduction , port ) => reduction . merge ( port ) , Map ( ) ) ; } return export function inLink ( state , nodeId ) { return state . getIn ( [ 'in' , nodeId ] ) . reduce ( ( reduction , port ) => reduction . merge ( port ) , Map ( ) ) ; } export default getDetachedLinks ;