@neo4j-nvl/react 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -106,14 +106,14 @@ export const BasicNvlWrapper = memo(forwardRef((_a, ref) => {
|
|
|
106
106
|
return nvlMethods.reduce((current, method) => (Object.assign(Object.assign({}, current), {
|
|
107
107
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
108
108
|
// @ts-ignore suppress the type casting error on spreading
|
|
109
|
-
[method]: (...args) =>
|
|
109
|
+
[method]: (...args) => nvlRef && nvlRef.current && nvlRef.current[method](...args) })), {});
|
|
110
110
|
});
|
|
111
111
|
const containerRef = useRef();
|
|
112
|
-
const
|
|
112
|
+
const nvlRef = useRef();
|
|
113
113
|
const [currentNodes, setCurrentNodes] = useState(nodes);
|
|
114
114
|
const [currentRels, setCurrentRels] = useState(rels);
|
|
115
115
|
useEffect(() => {
|
|
116
|
-
if (!
|
|
116
|
+
if (!nvlRef.current) {
|
|
117
117
|
const combinedOptions = Object.assign(Object.assign({}, nvlOptions), { layoutOptions });
|
|
118
118
|
if (layout) {
|
|
119
119
|
combinedOptions.layout = layout;
|
|
@@ -121,7 +121,7 @@ export const BasicNvlWrapper = memo(forwardRef((_a, ref) => {
|
|
|
121
121
|
let newNvl;
|
|
122
122
|
try {
|
|
123
123
|
newNvl = new NVL(containerRef.current, currentNodes, currentRels, combinedOptions, nvlCallbacks);
|
|
124
|
-
|
|
124
|
+
nvlRef.current = newNvl;
|
|
125
125
|
setCurrentRels(rels);
|
|
126
126
|
setCurrentNodes(nodes);
|
|
127
127
|
}
|
|
@@ -139,7 +139,7 @@ export const BasicNvlWrapper = memo(forwardRef((_a, ref) => {
|
|
|
139
139
|
}
|
|
140
140
|
}, []);
|
|
141
141
|
useEffect(() => {
|
|
142
|
-
if (!
|
|
142
|
+
if (!nvlRef.current) {
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
const nodeChanges = getMapDifferences(currentNodes, nodes);
|
|
@@ -147,21 +147,21 @@ export const BasicNvlWrapper = memo(forwardRef((_a, ref) => {
|
|
|
147
147
|
const relChanges = getMapDifferences(currentRels, rels);
|
|
148
148
|
setCurrentRels(rels);
|
|
149
149
|
setCurrentNodes(nodes);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
nvlRef.current && nvlRef.current.addAndUpdateElementsInGraph([...nodeChanges.added, ...nodeDiff], [...relChanges.added, ...relChanges.updated]);
|
|
151
|
+
nvlRef.current && nvlRef.current.removeRelationshipsWithIds(relChanges.removed.map((r) => r.id));
|
|
152
|
+
nvlRef.current && nvlRef.current.removeNodesWithIds(nodeChanges.removed.map((n) => n.id));
|
|
153
153
|
}, [nodes, rels]);
|
|
154
154
|
useEffect(() => {
|
|
155
|
-
|
|
155
|
+
nvlRef.current && nvlRef.current.setLayout(layout);
|
|
156
156
|
}, [layout]);
|
|
157
157
|
useDeepCompareEffect(() => {
|
|
158
|
-
|
|
158
|
+
nvlRef.current && nvlRef.current.setLayoutOptions(layoutOptions);
|
|
159
159
|
}, [layoutOptions]);
|
|
160
160
|
useEffect(() => {
|
|
161
|
-
|
|
161
|
+
nvlRef.current && nvlRef.current.setUseWebGLRenderer(nvlOptions.useWebGL);
|
|
162
162
|
}, [nvlOptions.useWebGL]);
|
|
163
163
|
useEffect(() => {
|
|
164
|
-
|
|
164
|
+
nvlRef.current && nvlRef.current.setDisableWebGL(nvlOptions.disableWebGL);
|
|
165
165
|
}, [nvlOptions.disableWebGL]);
|
|
166
166
|
return React.createElement("div", Object.assign({ ref: containerRef, style: { height: '100%', outline: '0' } }, nvlEvents));
|
|
167
167
|
}));
|