Browse Source

names memoized components

main
Steve Ruiz 4 years ago
parent
commit
75beaf2516
3 changed files with 33 additions and 25 deletions
  1. 1
    1
      components/canvas/defs.tsx
  2. 23
    19
      components/canvas/selected.tsx
  3. 9
    5
      components/canvas/shape.tsx

+ 1
- 1
components/canvas/defs.tsx View File

@@ -24,7 +24,7 @@ export default function Defs() {
24 24
   )
25 25
 }
26 26
 
27
-const Def = memo(({ id }: { id: string }) => {
27
+const Def = memo(function Def({ id }: { id: string }) {
28 28
   const shape = useSelector(({ data }) => getPage(data).shapes[id])
29 29
   if (!shape) return null
30 30
   return getShapeUtils(shape).render(shape)

+ 23
- 19
components/canvas/selected.tsx View File

@@ -25,34 +25,38 @@ export default function Selected() {
25 25
   )
26 26
 }
27 27
 
28
-export const ShapeOutline = memo(
29
-  ({ id, isSelected }: { id: string; isSelected: boolean }) => {
30
-    const rIndicator = useRef<SVGUseElement>(null)
28
+export const ShapeOutline = memo(function ShapeOutline({
29
+  id,
30
+  isSelected,
31
+}: {
32
+  id: string
33
+  isSelected: boolean
34
+}) {
35
+  const rIndicator = useRef<SVGUseElement>(null)
31 36
 
32
-    const shape = useSelector(({ data }) => getPage(data).shapes[id])
37
+  const shape = useSelector(({ data }) => getPage(data).shapes[id])
33 38
 
34
-    const events = useShapeEvents(id, rIndicator)
39
+  const events = useShapeEvents(id, rIndicator)
35 40
 
36
-    if (!shape) return null
41
+  if (!shape) return null
37 42
 
38
-    const transform = `
43
+  const transform = `
39 44
     rotate(${shape.rotation * (180 / Math.PI)},
40 45
     ${getShapeUtils(shape).getCenter(shape)})
41 46
     translate(${shape.point})
42 47
   `
43 48
 
44
-    return (
45
-      <SelectIndicator
46
-        ref={rIndicator}
47
-        as="use"
48
-        href={'#' + id}
49
-        transform={transform}
50
-        isLocked={shape.isLocked}
51
-        {...events}
52
-      />
53
-    )
54
-  }
55
-)
49
+  return (
50
+    <SelectIndicator
51
+      ref={rIndicator}
52
+      as="use"
53
+      href={'#' + id}
54
+      transform={transform}
55
+      isLocked={shape.isLocked}
56
+      {...events}
57
+    />
58
+  )
59
+})
56 60
 
57 61
 const SelectIndicator = styled('path', {
58 62
   zStrokeWidth: 3,

+ 9
- 5
components/canvas/shape.tsx View File

@@ -47,11 +47,15 @@ function Shape({ id, isSelecting }: { id: string; isSelecting: boolean }) {
47 47
   )
48 48
 }
49 49
 
50
-const RealShape = memo(
51
-  ({ id, style }: { id: string; style: ReturnType<typeof getShapeStyle> }) => {
52
-    return <StyledShape as="use" href={'#' + id} {...style} />
53
-  }
54
-)
50
+const RealShape = memo(function RealShape({
51
+  id,
52
+  style,
53
+}: {
54
+  id: string
55
+  style: ReturnType<typeof getShapeStyle>
56
+}) {
57
+  return <StyledShape as="use" href={'#' + id} {...style} />
58
+})
55 59
 
56 60
 const StyledShape = styled('path', {
57 61
   strokeLinecap: 'round',

Loading…
Cancel
Save