瀏覽代碼

names memoized components

main
Steve Ruiz 4 年之前
父節點
當前提交
75beaf2516
共有 3 個文件被更改,包括 33 次插入25 次删除
  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 查看文件

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

+ 23
- 19
components/canvas/selected.tsx 查看文件

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
     rotate(${shape.rotation * (180 / Math.PI)},
44
     rotate(${shape.rotation * (180 / Math.PI)},
40
     ${getShapeUtils(shape).getCenter(shape)})
45
     ${getShapeUtils(shape).getCenter(shape)})
41
     translate(${shape.point})
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
 const SelectIndicator = styled('path', {
61
 const SelectIndicator = styled('path', {
58
   zStrokeWidth: 3,
62
   zStrokeWidth: 3,

+ 9
- 5
components/canvas/shape.tsx 查看文件

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
 const StyledShape = styled('path', {
60
 const StyledShape = styled('path', {
57
   strokeLinecap: 'round',
61
   strokeLinecap: 'round',

Loading…
取消
儲存