Skip to content

Commit 0f2ea98

Browse files
author
Nicolas ERNY
authored
Improve bundle size: remove gojs global import (#122)
1 parent 7dfe324 commit 0f2ea98

3 files changed

Lines changed: 40 additions & 29 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-gojs",
3-
"version": "4.7.2",
3+
"version": "4.8.0",
44
"description": "GoJS React integration",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/GojsDiagram.test.tsx

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import * as React from 'react';
2-
import * as go from 'gojs';
3-
import { Diagram } from 'gojs';
2+
import {
3+
Diagram,
4+
GraphObject,
5+
Spot,
6+
Node,
7+
Shape,
8+
TextBlock,
9+
Group,
10+
Panel,
11+
Binding,
12+
Placeholder,
13+
Size,
14+
LayeredDigraphLayout
15+
} from 'gojs';
416
import { mount } from 'enzyme';
517
import GojsDiagram, { GojsModel } from './GojsDiagram';
618
import { ModelChangeEventType } from './modelChangeEvent';
@@ -30,44 +42,44 @@ describe('<GojsDiagram />', () => {
3042
};
3143

3244
const createDiagram = (diagramId: string): Diagram => {
33-
const $ = go.GraphObject.make;
45+
const $ = GraphObject.make;
3446

35-
const myDiagram: Diagram = $(go.Diagram, diagramId, {
36-
initialContentAlignment: go.Spot.LeftCenter
47+
const myDiagram: Diagram = $(Diagram, diagramId, {
48+
initialContentAlignment: Spot.LeftCenter
3749
});
3850

3951
myDiagram.nodeTemplate = $(
40-
go.Node,
52+
Node,
4153
'Auto',
42-
$(go.Shape, 'RoundedRectangle', { strokeWidth: 0 }, new go.Binding('fill', 'color')),
43-
$(go.TextBlock, { margin: 8 }, new go.Binding('text', 'key')),
44-
makePort(portTo, go.Spot.LeftCenter, false, true),
45-
makePort(portFrom, go.Spot.RightCenter, true, false)
54+
$(Shape, 'RoundedRectangle', { strokeWidth: 0 }, new Binding('fill', 'color')),
55+
$(TextBlock, { margin: 8 }, new Binding('text', 'key')),
56+
makePort(portTo, Spot.LeftCenter, false, true),
57+
makePort(portFrom, Spot.RightCenter, true, false)
4658
);
4759

4860
myDiagram.groupTemplate = $(
49-
go.Group,
61+
Group,
5062
'Vertical',
5163
$(
52-
go.Panel,
64+
Panel,
5365
'Auto',
54-
$(go.Shape, 'RoundedRectangle', {
66+
$(Shape, 'RoundedRectangle', {
5567
parameter1: 14,
5668
fill: 'rgba(128,128,128,0.33)'
5769
}),
58-
$(go.Placeholder, { padding: 5 })
70+
$(Placeholder, { padding: 5 })
5971
),
60-
$(go.TextBlock, { alignment: go.Spot.Right, font: 'Bold 12pt Sans-Serif' }, new go.Binding('text', 'key'))
72+
$(TextBlock, { alignment: Spot.Right, font: 'Bold 12pt Sans-Serif' }, new Binding('text', 'key'))
6173
);
6274

6375
return myDiagram;
6476
};
6577

66-
const makePort = (name: string, spot: go.Spot, isOutput: boolean, isInput: boolean) => {
67-
const $ = go.GraphObject.make;
68-
return $(go.Shape, 'Circle', {
78+
const makePort = (name: string, spot: Spot, isOutput: boolean, isInput: boolean) => {
79+
const $ = GraphObject.make;
80+
return $(Shape, 'Circle', {
6981
fill: 'black',
70-
desiredSize: new go.Size(8, 8),
82+
desiredSize: new Size(8, 8),
7183
alignment: spot,
7284
alignmentFocus: spot,
7385
fromSpot: spot,
@@ -83,7 +95,7 @@ describe('<GojsDiagram />', () => {
8395

8496
const updateDiagramProps = (myDiagram: Diagram): void => {
8597
// The function could kept empty or we can add diagram properties that we wish to change. The reason to make this function user defined is to give more customization options to user. And also, its bit difficult to cover all the use cases of the charting library.
86-
myDiagram.layout = go.GraphObject.make(go.LayeredDigraphLayout, { direction: 90 });
98+
myDiagram.layout = GraphObject.make(LayeredDigraphLayout, { direction: 90 });
8799
};
88100

89101
const myDiagramId = 'myDiagramId';

src/GojsDiagram.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
2-
import * as go from 'gojs';
3-
import { Diagram, ChangedEvent, ObjectData } from 'gojs';
2+
import { Diagram, ChangedEvent, ObjectData, Key, Model, GraphObject, GraphLinksModel } from 'gojs';
43
import { DiagramModel, BaseNodeModel, LinkModel } from './model';
54
import { ModelChangeEvent } from './modelChangeEvent';
65
import {
@@ -24,14 +23,14 @@ export interface GojsDiagramProps<N extends BaseNodeModel, L extends LinkModel>
2423
linkToPortIdProperty?: string;
2524
nodeCategoryProperty?: string;
2625
linkKeyProperty?: string;
27-
makeUniqueKeyFunction?: () => go.Key;
28-
makeUniqueLinkKeyFunction?: () => go.Key;
29-
copyNodeDataFunction?: (data: ObjectData, model: go.Model) => ObjectData;
26+
makeUniqueKeyFunction?: () => Key;
27+
makeUniqueLinkKeyFunction?: () => Key;
28+
copyNodeDataFunction?: (data: ObjectData, model: Model) => ObjectData;
3029
updateDiagramProps?: (myDiagram: Diagram) => void;
3130
defaultSelectedNode?: string;
3231
}
3332

34-
export interface GojsModel extends go.Model {
33+
export interface GojsModel extends Model {
3534
linkDataArray: ObjectData[];
3635
addLinkDataCollection: (links: ObjectData[]) => void;
3736
removeLinkDataCollection: (links: ObjectData[]) => void;
@@ -120,7 +119,7 @@ class GojsDiagram<N extends BaseNodeModel, L extends LinkModel> extends React.Pu
120119
this.myDiagram.addModelChangedListener(this.modelChangedHandler);
121120
}
122121

123-
this.myDiagram.model = go.GraphObject.make(go.GraphLinksModel, {
122+
this.myDiagram.model = GraphObject.make(GraphLinksModel, {
124123
...(this.props.makeUniqueKeyFunction && {
125124
makeUniqueKeyFunction: this.props.makeUniqueKeyFunction
126125
}),
@@ -214,7 +213,7 @@ class GojsDiagram<N extends BaseNodeModel, L extends LinkModel> extends React.Pu
214213

215214
private applyUpdatesFromModel() {
216215
this.myDiagram.model.applyIncrementalJson({
217-
class: 'go.GraphLinksModel',
216+
class: 'GraphLinksModel',
218217
incremental: 1,
219218
nodeKeyProperty: 'key',
220219
linkKeyProperty: 'key',

0 commit comments

Comments
 (0)