* Updates Dependencies

* Uses webpack to bundle runtime library into a single file
* Inject the entire file into the Debugee
* Register runtime helpers (hediet_dbgVis)
This commit is contained in:
Henning Dieterichs
2020-02-12 14:20:45 +01:00
parent 1a2d5b9af0
commit d4c6e942d0
29 changed files with 809 additions and 669 deletions

View File

@@ -0,0 +1,68 @@
import {
CommonDataTypes,
EdgeGraphData,
NodeGraphData,
} from "../../CommonDataTypes";
/**
* Given a list of roots, it creates a graph by following their edges recursively.
* Tracks cycles.
*/
export function createGraph<T>(
roots: T[],
infoSelector: (
item: T
) => {
id?: string | number;
edges: ({ to: T } & Omit<EdgeGraphData, "from" | "to">)[];
} & Omit<NodeGraphData, "id">
): CommonDataTypes.Graph {
const r: CommonDataTypes.Graph = {
kind: {
graph: true,
},
nodes: [],
edges: [],
};
let idCounter = 1;
const ids = new Map<T, string>();
function getId(item: T): string {
const _id = infoSelector(item).id;
if (_id !== undefined) {
return "" + _id;
}
let id = ids.get(item);
if (!id) {
id = `hediet.de/id-${idCounter++}`;
ids.set(item, id);
}
return id;
}
const queue = new Array<T>(...roots);
const processed = new Set<T>();
while (queue.length > 0) {
const item = queue.shift()!;
if (processed.has(item)) {
continue;
}
processed.add(item);
const nodeInfo = infoSelector(item);
const fromId = getId(item);
r.nodes.push({ ...nodeInfo, id: fromId, ["edges" as any]: undefined });
for (const e of nodeInfo.edges) {
const toId = getId(e.to);
r.edges.push({
...e,
from: fromId,
to: toId,
});
if (!processed.has(e.to)) {
queue.push(e.to);
}
}
}
return r;
}