Skip to content

Commit

Permalink
feat(rstream-dot): support multiple roots in walk()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 24, 2018
1 parent 0153903 commit 704025a
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/rstream-dot/src/index.ts
Expand Up @@ -53,26 +53,29 @@ const dotNode = (s: Node, opts: DotOpts) => {
return res + "];"
};

export const walk = (sub: Subscription<any, any>, state: WalkState) => {
if (state.subs.get(sub)) return state;
const id = state.id;
const desc = { id, label: sub.id || "<noid>", type: getNodeType(sub) };
state.subs.set(sub, desc);
state.id++;
const children = (<any>sub).subs ||
((<any>sub).__owner ?
[(<any>sub).__owner] :
undefined);
if (children) {
for (let s of children) {
walk(s, state);
state.rels.push([desc, state.subs.get(s)]);
export const walk = (subs: Subscription<any, any>[], state?: WalkState) => {
state || (state = { id: 0, subs: new Map(), rels: [] });
for (let sub of subs) {
if (state.subs.get(sub)) return state;
const id = state.id;
const desc = { id, label: sub.id || "<noid>", type: getNodeType(sub) };
state.subs.set(sub, desc);
state.id++;
const children = (<any>sub).subs ||
((<any>sub).__owner ?
[(<any>sub).__owner] :
undefined);
if (children) {
for (let s of children) {
walk([s], state);
state.rels.push([desc, state.subs.get(s)]);
}
}
}
return state;
}

export const toDot = (state: WalkState, opts: Partial<DotOpts>) => {
export const toDot = (state: WalkState, opts?: Partial<DotOpts>) => {
opts = Object.assign({
font: "Inconsolata",
fontsize: 11,
Expand Down

0 comments on commit 704025a

Please sign in to comment.