File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,11 @@ declare module "ngraph.graph" {
120120 */
121121 getLink : ( fromNodeId : NodeId , toNodeId : NodeId ) => Link < LinkData > | undefined
122122
123+ /**
124+ * Returns a link by its id
125+ */
126+ getLinkById : ( linkId : LinkId ) => Link < LinkData > | undefined ;
127+
123128 /**
124129 * Checks if link is present in the graph
125130 */
Original file line number Diff line number Diff line change @@ -246,7 +246,16 @@ function createGraph(options) {
246246 *
247247 * @returns link if there is one; undefined otherwise.
248248 */
249- getLink : getLink
249+ getLink : getLink ,
250+
251+ /**
252+ * Gets a link by its id.
253+ *
254+ * @param {string } linkId link identifier
255+ *
256+ * @returns link if there is one; undefined otherwise.
257+ */
258+ getLinkById : getLinkById
250259 } ;
251260
252261 // this will add `on()` and `fire()` methods.
@@ -445,6 +454,11 @@ function createGraph(options) {
445454 return links . get ( makeLinkId ( fromNodeId , toNodeId ) ) ;
446455 }
447456
457+ function getLinkById ( linkId ) {
458+ if ( linkId === undefined ) return undefined ;
459+ return links . get ( linkId ) ;
460+ }
461+
448462 function clear ( ) {
449463 enterModification ( ) ;
450464 forEachNode ( function ( node ) {
Original file line number Diff line number Diff line change @@ -45,6 +45,13 @@ test('hasLink is the same as getLink', function () {
4545 expect ( graph . getLink ) . toBe ( graph . hasLink ) ;
4646} ) ;
4747
48+ test ( 'getLinkById gets link by id' , function ( ) {
49+ var graph = createGraph ( ) ;
50+ var link = graph . addLink ( 1 , 2 ) ;
51+ var fetchedLink = graph . getLinkById ( link . id ) ;
52+ expect ( fetchedLink ) . toBe ( link ) ;
53+ } ) ;
54+
4855test ( 'it considers uniqueLinkId as multigraph' , function ( ) {
4956 var options = { uniqueLinkId : true } ;
5057 createGraph ( options ) ;
You can’t perform that action at this time.
0 commit comments