From c3c23ea16a35658ac59a866bd18cf0a4420a0053 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Fri, 13 Aug 2021 11:27:43 +0200 Subject: [PATCH] fix: :bug: mergeGs was trying to copy the first graph in an arr of graphs, but that arr could be empty --- src/sharedFunctions.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index ceea7141..f621d4e8 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -1,4 +1,4 @@ -import type { Graph } from "graphlib"; +import { Graph } from "graphlib"; import * as graphlib from "graphlib"; import { parseTypedLink } from "juggl-api"; import { @@ -450,15 +450,13 @@ export function mergeGraphs(g1: Graph, g2: Graph) { } export function mergeGs(...graphs: Graph[]) { - const copy = graphlib.json.read(graphlib.json.write(graphs[0])); - graphs.forEach((graph, i) => { - if (i > 0) { - graph.edges().forEach((edge) => { - copy.setEdge(edge); - }); - } + const outG = new Graph(); + graphs.forEach((graph) => { + graph.edges().forEach((edge) => { + outG.setEdge(edge); + }); }); - return copy; + return outG; } export function removeUnlinkedNodes(g: Graph) {