Skip to content

Commit

Permalink
Merge pull request #157 from AykutSarac/editor-perf
Browse files Browse the repository at this point in the history
Improve Editor Rerender Performance
  • Loading branch information
AykutSarac authored Sep 11, 2022
2 parents 1b7e7a6 + 8c98963 commit d7d90ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/components/CustomNode/ObjectNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import * as Styled from "./styles";

const inViewport = true;

const ObjectNode: React.FC<CustomNodeProps<[string, string][]>> = ({
type ObjectNodeProps = CustomNodeProps<[string, string][]>;

const ObjectNode: React.FC<ObjectNodeProps> = ({
width,
height,
value,
Expand Down Expand Up @@ -46,4 +48,8 @@ const ObjectNode: React.FC<CustomNodeProps<[string, string][]>> = ({
);
};

export default ObjectNode;
function propsAreEqual(prev: ObjectNodeProps, next: ObjectNodeProps) {
return prev.width === next.width && prev.height === next.height;
}

export default React.memo(ObjectNode, propsAreEqual);
15 changes: 11 additions & 4 deletions src/components/CustomNode/TextNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ const StyledTextNodeWrapper = styled.div<{ hasCollapse: boolean }>`
width: 100%;
`;

const TextNode: React.FC<
CustomNodeProps<string> & { node: NodeData; hasCollapse: boolean }
> = ({
type TextNodeProps = CustomNodeProps<string> & {
node: NodeData;
hasCollapse: boolean;
};

const TextNode: React.FC<TextNodeProps> = ({
node,
width,
height,
Expand Down Expand Up @@ -99,4 +102,8 @@ const TextNode: React.FC<
);
};

export default TextNode;
function propsAreEqual(prev: TextNodeProps, next: TextNodeProps) {
return prev.value === next.value;
}

export default React.memo(TextNode, propsAreEqual);
10 changes: 2 additions & 8 deletions src/components/CustomNode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Label, Node, NodeProps } from "reaflow";
import { Node, NodeProps } from "reaflow";
import ObjectNode from "./ObjectNode";
import TextNode from "./TextNode";

Expand All @@ -12,17 +12,11 @@ export interface CustomNodeProps<T> {
y: number;
}

const baseLabelStyle = {
fill: "transparent",
stroke: "transparent",
strokeWidth: 0,
};

export const CustomNode = (nodeProps: NodeProps) => {
const { properties } = nodeProps;

return (
<Node {...nodeProps} label={<Label style={baseLabelStyle} />}>
<Node {...nodeProps} label={<React.Fragment />}>
{({ width, height, x, y, node }) => {
if (Array.isArray(properties.text)) {
return (
Expand Down

0 comments on commit d7d90ad

Please sign in to comment.