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

Commit a1d0673

Browse files
authored
chore: Huge refactor of the graph state management logic (#106)
* Add graph layout settings * Start huge refactor * Finish graph data context * Fix wrong types imports
1 parent cc28705 commit a1d0673

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1284
-769
lines changed
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
1+
import { memo } from 'react';
2+
3+
import GraphProvider from '@/contexts/GraphContext';
14
import { DirectedGraph } from '@/models/graphs';
25
import { DirectedGraphRenderers } from '@/types/renderer';
36
import { DirectedGraphSettings } from '@/types/settings';
7+
import { deepMemoComparator } from '@/utils/equality';
48

5-
import GraphComponent, { GraphComponentPrivateProps } from './GraphComponent';
9+
import GraphComponent, { GraphComponentProps } from './GraphComponent';
610

711
type DirectedGraphComponentProps<V, E> = {
812
graph: DirectedGraph<V, E>;
913
settings?: DirectedGraphSettings<V, E>;
1014
renderers?: DirectedGraphRenderers<V, E>;
1115
};
1216

13-
function DirectedGraphComponent<V, E>(
14-
props: DirectedGraphComponentProps<V, E> & GraphComponentPrivateProps<V, E>
15-
) {
16-
return <GraphComponent {...props} />;
17-
}
17+
function DirectedGraphComponent<V, E>({
18+
boundingRect,
19+
onRender,
20+
...providerProps
21+
}: DirectedGraphComponentProps<V, E> & GraphComponentProps) {
22+
console.log('DirectedGraphComponent');
1823

19-
export default <V, E>(props: DirectedGraphComponentProps<V, E>) => {
2024
return (
21-
<DirectedGraphComponent
22-
{...(props as DirectedGraphComponentProps<V, E> &
23-
GraphComponentPrivateProps<V, E>)}
24-
/>
25+
<GraphProvider {...providerProps}>
26+
<GraphComponent boundingRect={boundingRect} onRender={onRender} />
27+
</GraphProvider>
2528
);
26-
};
29+
}
30+
31+
export default memo(
32+
<V, E>(props: DirectedGraphComponentProps<V, E>) => {
33+
return (
34+
<DirectedGraphComponent
35+
{...(props as DirectedGraphComponentProps<V, E> & GraphComponentProps)}
36+
/>
37+
);
38+
},
39+
deepMemoComparator({
40+
shallow: ['graph'],
41+
exclude: ['boundingRect']
42+
})
43+
);

0 commit comments

Comments
 (0)