Skip to content
This repository was archived by the owner on Mar 17, 2024. It is now read-only.

Commit 6d98e99

Browse files
authored
Merge pull request #91 from ts-graphviz/upgrade-ts-graphviz
upgrade ts-graphviz to v0.12.0
2 parents 5f484ca + 07de21e commit 6d98e99

13 files changed

+33
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"rollup": "^2.6.1",
8686
"rollup-plugin-terser": "^5.3.0",
8787
"rollup-plugin-typescript2": "^0.27.0",
88-
"ts-graphviz": "^0.10.0",
88+
"ts-graphviz": "^0.12.0",
8989
"ts-jest": "^25.3.1",
9090
"ts-loader": "^7.0.2",
9191
"ts-node": "^8.9.1",

src/components/__tests__/utils/renderExpectToThrow.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable react/destructuring-assignment */
22
/* eslint-disable @typescript-eslint/explicit-function-return-type */
33
import React, { Component, ReactElement } from 'react';
4-
import { Context } from 'ts-graphviz';
54
import { render } from '../../../renderer/render';
65

76
export function renderExpectToThrow(element: ReactElement, expectedError: string) {
@@ -28,9 +27,8 @@ export function renderExpectToThrow(element: ReactElement, expectedError: string
2827
}
2928
}
3029

31-
const context = new Context();
3230
try {
33-
render(<ErrorBoundary>{element}</ErrorBoundary>, context);
31+
render(<ErrorBoundary>{element}</ErrorBoundary>, {});
3432
} catch (e) {
3533
errors.push(e);
3634
}

src/components/contexts/Cluster.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { ICluster } from 'ts-graphviz';
33

4-
export const NoCluster = {} as ICluster<string>;
5-
export const Cluster = React.createContext<ICluster<string>>(NoCluster);
4+
export const NoCluster = {} as ICluster;
5+
export const Cluster = React.createContext<ICluster>(NoCluster);
66
Cluster.displayName = 'Cluster';
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from 'react';
2-
import { Context } from 'ts-graphviz';
2+
import { IRootCluster } from 'ts-graphviz';
33

4-
export const NoContext = {} as Context;
4+
export type Context = {
5+
root?: IRootCluster;
6+
};
7+
8+
export const NoContext = {};
59

610
export const GraphvizContext = React.createContext<Context>(NoContext);
711
GraphvizContext.displayName = 'GraphvizContext';

src/hooks/__tests__/use-graphviz-context.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { Context } from 'ts-graphviz';
21
import { renderHook } from '@testing-library/react-hooks';
32
import { context } from './utils/wrapper';
43
import { useGraphvizContext } from '../use-graphviz-context';
54
import { NoGraphvizContextErrorMessage } from '../../utils/errors';
65

76
describe('useGraphvizContext', () => {
8-
test('returns Context instance', () => {
7+
test('returns {}', () => {
98
const { result } = renderHook(() => useGraphvizContext(), {
109
wrapper: context(),
1110
});
12-
expect(result.current).toBeInstanceOf(Context);
11+
expect(result.current).toStrictEqual({});
1312
});
1413

1514
test('An error occurs when called outside the GraphvizContext', () => {

src/hooks/__tests__/utils/wrapper.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
/* eslint-disable react/jsx-props-no-spreading */
22
/* eslint-disable @typescript-eslint/explicit-function-return-type */
33
import React, { FC, ComponentProps } from 'react';
4-
import { Context } from 'ts-graphviz';
4+
55
import { Digraph } from '../../../components/Digraph';
66
import { Graph } from '../../../components/Graph';
77
import { GraphvizContext } from '../../../components/contexts/GraphvizContext';
88
import { Subgraph } from '../../../components/Subgraph';
99

1010
export const context = (): FC => ({ children }) => {
11-
const ctx = new Context();
12-
return <GraphvizContext.Provider value={ctx}>{children}</GraphvizContext.Provider>;
11+
return <GraphvizContext.Provider value={{}}>{children}</GraphvizContext.Provider>;
1312
};
1413

1514
export const digraph = (props: ComponentProps<typeof Digraph> = {}): FC => ({ children }) => {
16-
const ctx = new Context();
1715
return (
18-
<GraphvizContext.Provider value={ctx}>
16+
<GraphvizContext.Provider value={{}}>
1917
<Digraph {...props}>{children}</Digraph>
2018
</GraphvizContext.Provider>
2119
);
2220
};
2321

2422
export const digraphInSubgraph = (props: ComponentProps<typeof Subgraph> = {}): FC => ({ children }) => {
25-
const ctx = new Context();
2623
return (
27-
<GraphvizContext.Provider value={ctx}>
24+
<GraphvizContext.Provider value={{}}>
2825
<Digraph>
2926
<Subgraph {...props}>{children}</Subgraph>
3027
</Digraph>
@@ -33,18 +30,16 @@ export const digraphInSubgraph = (props: ComponentProps<typeof Subgraph> = {}):
3330
};
3431

3532
export const graph = (props: ComponentProps<typeof Graph> = {}): FC => ({ children }) => {
36-
const ctx = new Context();
3733
return (
38-
<GraphvizContext.Provider value={ctx}>
34+
<GraphvizContext.Provider value={{}}>
3935
<Graph {...props}>{children}</Graph>
4036
</GraphvizContext.Provider>
4137
);
4238
};
4339

4440
export const graphInSubgraph = (props: ComponentProps<typeof Subgraph> = {}): FC => ({ children }) => {
45-
const ctx = new Context();
4641
return (
47-
<GraphvizContext.Provider value={ctx}>
42+
<GraphvizContext.Provider value={{}}>
4843
<Graph>
4944
<Subgraph {...props}>{children}</Subgraph>
5045
</Graph>

src/hooks/use-cluster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ICluster } from 'ts-graphviz';
33
import { Cluster, NoCluster } from '../components/contexts/Cluster';
44
import { NoClusterErrorMessage } from '../utils/errors';
55

6-
export const useCluster = <T extends string>(): ICluster<T> => {
6+
export const useCluster = (): ICluster => {
77
const cluster = useContext(Cluster);
88
if (cluster === NoCluster) {
99
throw Error(NoClusterErrorMessage);

src/hooks/use-digraph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export type DigraphProps = {
1313
export const useDigraph = ({ id, comment, edge, node, graph, ...attributes }: DigraphProps = {}): Digraph => {
1414
const context = useGraphvizContext();
1515
const digraph = useMemo(() => {
16-
const g = new Digraph(context, id);
16+
const g = new Digraph(id);
17+
context.root = g;
1718
g.comment = comment;
1819
g.apply(attributes);
1920
g.attributes.node.apply(node ?? {});

src/hooks/use-edge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const useEdge = ({ targets, comment, ...attributes }: EdgeProps): IEdge =
1616
throw Error(EdgeTargetLengthErrorMessage);
1717
}
1818
const edge = useMemo(() => {
19-
const e = cluster.createEdge(...targets);
19+
const e = cluster.createEdge(targets);
2020
e.comment = comment;
2121
e.attributes.apply(attributes);
2222
return e;

src/hooks/use-graph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export type GraphProps = {
1616
export const useGraph = ({ id, comment, edge, node, graph, ...attributes }: GraphProps = {}): Graph => {
1717
const context = useGraphvizContext();
1818
const memoGraph = useMemo(() => {
19-
const g = new Graph(context, id);
19+
const g = new Graph(id);
20+
context.root = g;
2021
g.comment = comment;
2122
g.apply(attributes);
2223
g.attributes.node.apply(node ?? {});

src/hooks/use-graphviz-context.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useContext } from 'react';
2-
import { Context } from 'ts-graphviz';
3-
import { GraphvizContext, NoContext } from '../components/contexts/GraphvizContext';
2+
import { GraphvizContext, NoContext, Context } from '../components/contexts/GraphvizContext';
43
import { NoGraphvizContextErrorMessage } from '../utils/errors';
54

65
export const useGraphvizContext = (): Context => {

src/renderer/render.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReactElement, createElement } from 'react';
2-
import { Context } from 'ts-graphviz';
3-
import { GraphvizContext } from '../components/contexts/GraphvizContext';
2+
import { toDot } from 'ts-graphviz';
3+
import { GraphvizContext, Context } from '../components/contexts/GraphvizContext';
44
import { reconciler } from './reconciler';
55

66
const noop = (): void => undefined;
@@ -22,7 +22,7 @@ export function render(element: ReactElement, context: Context): number {
2222
}
2323

2424
export function renderToDot(element: ReactElement): string {
25-
const context = new Context();
25+
const context: Context = {};
2626
render(element, context);
27-
return context.root?.toDot() || '';
27+
return context.root ? toDot(context.root) : '';
2828
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11397,10 +11397,10 @@ ts-dedent@^1.1.0:
1139711397
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-1.1.1.tgz#68fad040d7dbd53a90f545b450702340e17d18f3"
1139811398
integrity sha512-UGTRZu1evMw4uTPyYF66/KFd22XiU+jMaIuHrkIHQ2GivAXVlLV0v/vHrpOuTRf9BmpNHi/SO7Vd0rLu0y57jg==
1139911399

11400-
ts-graphviz@^0.10.0:
11401-
version "0.10.0"
11402-
resolved "https://registry.yarnpkg.com/ts-graphviz/-/ts-graphviz-0.10.0.tgz#b88f46c178c6c77682c202000d64c962e3417f0d"
11403-
integrity sha512-jX1b2KPyKReHUTwLgsGL8bcASqjgMGVSbOr8xnrocInr3YeGnsOzI/78xyTgRLGqayVUBod+2xKDZdSyg0rtEw==
11400+
ts-graphviz@^0.12.0:
11401+
version "0.12.0"
11402+
resolved "https://registry.yarnpkg.com/ts-graphviz/-/ts-graphviz-0.12.0.tgz#fbbeaee6de632c1f553c3da517f7043a5fc09af9"
11403+
integrity sha512-Z99dqQXsDZmE+WXUXq3vf/Xzk8jmKqFotPHXucSl14hPfWZnu5ASMz5Wleila196RMPIyfY/4GLQTDtq+ySd9Q==
1140411404
dependencies:
1140511405
tslib "^1.10.0"
1140611406

0 commit comments

Comments
 (0)