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

upgrade ts-graphviz to v0.12.0 #91

Merged
merged 1 commit into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"rollup": "^2.6.1",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-typescript2": "^0.27.0",
"ts-graphviz": "^0.10.0",
"ts-graphviz": "^0.12.0",
"ts-jest": "^25.3.1",
"ts-loader": "^7.0.2",
"ts-node": "^8.9.1",
Expand Down
4 changes: 1 addition & 3 deletions src/components/__tests__/utils/renderExpectToThrow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable react/destructuring-assignment */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import React, { Component, ReactElement } from 'react';
import { Context } from 'ts-graphviz';
import { render } from '../../../renderer/render';

export function renderExpectToThrow(element: ReactElement, expectedError: string) {
Expand All @@ -28,9 +27,8 @@ export function renderExpectToThrow(element: ReactElement, expectedError: string
}
}

const context = new Context();
try {
render(<ErrorBoundary>{element}</ErrorBoundary>, context);
render(<ErrorBoundary>{element}</ErrorBoundary>, {});
} catch (e) {
errors.push(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/contexts/Cluster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ICluster } from 'ts-graphviz';

export const NoCluster = {} as ICluster<string>;
export const Cluster = React.createContext<ICluster<string>>(NoCluster);
export const NoCluster = {} as ICluster;
export const Cluster = React.createContext<ICluster>(NoCluster);
Cluster.displayName = 'Cluster';
8 changes: 6 additions & 2 deletions src/components/contexts/GraphvizContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import { Context } from 'ts-graphviz';
import { IRootCluster } from 'ts-graphviz';

export const NoContext = {} as Context;
export type Context = {
root?: IRootCluster;
};

export const NoContext = {};

export const GraphvizContext = React.createContext<Context>(NoContext);
GraphvizContext.displayName = 'GraphvizContext';
5 changes: 2 additions & 3 deletions src/hooks/__tests__/use-graphviz-context.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Context } from 'ts-graphviz';
import { renderHook } from '@testing-library/react-hooks';
import { context } from './utils/wrapper';
import { useGraphvizContext } from '../use-graphviz-context';
import { NoGraphvizContextErrorMessage } from '../../utils/errors';

describe('useGraphvizContext', () => {
test('returns Context instance', () => {
test('returns {}', () => {
const { result } = renderHook(() => useGraphvizContext(), {
wrapper: context(),
});
expect(result.current).toBeInstanceOf(Context);
expect(result.current).toStrictEqual({});
});

test('An error occurs when called outside the GraphvizContext', () => {
Expand Down
17 changes: 6 additions & 11 deletions src/hooks/__tests__/utils/wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
/* eslint-disable react/jsx-props-no-spreading */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import React, { FC, ComponentProps } from 'react';
import { Context } from 'ts-graphviz';

import { Digraph } from '../../../components/Digraph';
import { Graph } from '../../../components/Graph';
import { GraphvizContext } from '../../../components/contexts/GraphvizContext';
import { Subgraph } from '../../../components/Subgraph';

export const context = (): FC => ({ children }) => {
const ctx = new Context();
return <GraphvizContext.Provider value={ctx}>{children}</GraphvizContext.Provider>;
return <GraphvizContext.Provider value={{}}>{children}</GraphvizContext.Provider>;
};

export const digraph = (props: ComponentProps<typeof Digraph> = {}): FC => ({ children }) => {
const ctx = new Context();
return (
<GraphvizContext.Provider value={ctx}>
<GraphvizContext.Provider value={{}}>
<Digraph {...props}>{children}</Digraph>
</GraphvizContext.Provider>
);
};

export const digraphInSubgraph = (props: ComponentProps<typeof Subgraph> = {}): FC => ({ children }) => {
const ctx = new Context();
return (
<GraphvizContext.Provider value={ctx}>
<GraphvizContext.Provider value={{}}>
<Digraph>
<Subgraph {...props}>{children}</Subgraph>
</Digraph>
Expand All @@ -33,18 +30,16 @@ export const digraphInSubgraph = (props: ComponentProps<typeof Subgraph> = {}):
};

export const graph = (props: ComponentProps<typeof Graph> = {}): FC => ({ children }) => {
const ctx = new Context();
return (
<GraphvizContext.Provider value={ctx}>
<GraphvizContext.Provider value={{}}>
<Graph {...props}>{children}</Graph>
</GraphvizContext.Provider>
);
};

export const graphInSubgraph = (props: ComponentProps<typeof Subgraph> = {}): FC => ({ children }) => {
const ctx = new Context();
return (
<GraphvizContext.Provider value={ctx}>
<GraphvizContext.Provider value={{}}>
<Graph>
<Subgraph {...props}>{children}</Subgraph>
</Graph>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ICluster } from 'ts-graphviz';
import { Cluster, NoCluster } from '../components/contexts/Cluster';
import { NoClusterErrorMessage } from '../utils/errors';

export const useCluster = <T extends string>(): ICluster<T> => {
export const useCluster = (): ICluster => {
const cluster = useContext(Cluster);
if (cluster === NoCluster) {
throw Error(NoClusterErrorMessage);
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/use-digraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export type DigraphProps = {
export const useDigraph = ({ id, comment, edge, node, graph, ...attributes }: DigraphProps = {}): Digraph => {
const context = useGraphvizContext();
const digraph = useMemo(() => {
const g = new Digraph(context, id);
const g = new Digraph(id);
context.root = g;
g.comment = comment;
g.apply(attributes);
g.attributes.node.apply(node ?? {});
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const useEdge = ({ targets, comment, ...attributes }: EdgeProps): IEdge =
throw Error(EdgeTargetLengthErrorMessage);
}
const edge = useMemo(() => {
const e = cluster.createEdge(...targets);
const e = cluster.createEdge(targets);
e.comment = comment;
e.attributes.apply(attributes);
return e;
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/use-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type GraphProps = {
export const useGraph = ({ id, comment, edge, node, graph, ...attributes }: GraphProps = {}): Graph => {
const context = useGraphvizContext();
const memoGraph = useMemo(() => {
const g = new Graph(context, id);
const g = new Graph(id);
context.root = g;
g.comment = comment;
g.apply(attributes);
g.attributes.node.apply(node ?? {});
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/use-graphviz-context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useContext } from 'react';
import { Context } from 'ts-graphviz';
import { GraphvizContext, NoContext } from '../components/contexts/GraphvizContext';
import { GraphvizContext, NoContext, Context } from '../components/contexts/GraphvizContext';
import { NoGraphvizContextErrorMessage } from '../utils/errors';

export const useGraphvizContext = (): Context => {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactElement, createElement } from 'react';
import { Context } from 'ts-graphviz';
import { GraphvizContext } from '../components/contexts/GraphvizContext';
import { toDot } from 'ts-graphviz';
import { GraphvizContext, Context } from '../components/contexts/GraphvizContext';
import { reconciler } from './reconciler';

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

export function renderToDot(element: ReactElement): string {
const context = new Context();
const context: Context = {};
render(element, context);
return context.root?.toDot() || '';
return context.root ? toDot(context.root) : '';
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11397,10 +11397,10 @@ ts-dedent@^1.1.0:
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-1.1.1.tgz#68fad040d7dbd53a90f545b450702340e17d18f3"
integrity sha512-UGTRZu1evMw4uTPyYF66/KFd22XiU+jMaIuHrkIHQ2GivAXVlLV0v/vHrpOuTRf9BmpNHi/SO7Vd0rLu0y57jg==

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

Expand Down