mirror of
https://github.com/penpot/penpot.git
synced 2025-06-13 16:31:39 +02:00
✨ Add proper memoization to the generic shape component.
This commit is contained in:
parent
39807186df
commit
a14073d170
1 changed files with 19 additions and 11 deletions
|
@ -21,22 +21,28 @@
|
||||||
[uxbox.main.ui.shapes.frame :as frame]
|
[uxbox.main.ui.shapes.frame :as frame]
|
||||||
[uxbox.main.refs :as refs]))
|
[uxbox.main.refs :as refs]))
|
||||||
|
|
||||||
(defn wrap-memo-shape
|
(defn- shape-wrapper-memo-equals?
|
||||||
([component]
|
[np op]
|
||||||
(mf/memo'
|
|
||||||
component
|
|
||||||
(fn [np op]
|
|
||||||
(let [n-shape (unchecked-get np "shape")
|
(let [n-shape (unchecked-get np "shape")
|
||||||
o-shape (unchecked-get op "shape")]
|
o-shape (unchecked-get op "shape")
|
||||||
(= n-shape o-shape))))))
|
n-frame (unchecked-get np "frame")
|
||||||
|
o-frame (unchecked-get op "frame")]
|
||||||
|
;; (prn "shape-wrapper-memo-equals?" (identical? n-frame o-frame))
|
||||||
|
(if (= (:type n-shape) :group)
|
||||||
|
false
|
||||||
|
(and (identical? n-shape o-shape)
|
||||||
|
(identical? n-frame o-frame)))))
|
||||||
|
|
||||||
(declare group-wrapper)
|
(declare group-wrapper)
|
||||||
(declare frame-wrapper)
|
(declare frame-wrapper)
|
||||||
|
|
||||||
(mf/defc shape-wrapper
|
(mf/defc shape-wrapper
|
||||||
{::mf/wrap [wrap-memo-shape]}
|
{::mf/wrap [#(mf/memo' % shape-wrapper-memo-equals?)]
|
||||||
[{:keys [shape frame] :as props}]
|
::mf/wrap-props false}
|
||||||
(let [opts #js {:shape shape :frame frame}]
|
[props]
|
||||||
|
(let [shape (unchecked-get props "shape")
|
||||||
|
frame (unchecked-get props "frame")
|
||||||
|
opts #js {:shape shape :frame frame}]
|
||||||
(when (and shape (not (:hidden shape)))
|
(when (and shape (not (:hidden shape)))
|
||||||
(case (:type shape)
|
(case (:type shape)
|
||||||
:group [:> group-wrapper opts]
|
:group [:> group-wrapper opts]
|
||||||
|
@ -47,6 +53,8 @@
|
||||||
:path [:> path/path-wrapper opts]
|
:path [:> path/path-wrapper opts]
|
||||||
:image [:> image/image-wrapper opts]
|
:image [:> image/image-wrapper opts]
|
||||||
:circle [:> circle/circle-wrapper opts]
|
:circle [:> circle/circle-wrapper opts]
|
||||||
|
|
||||||
|
;; Only used when drawing a new frame.
|
||||||
:frame [:> frame-wrapper opts]
|
:frame [:> frame-wrapper opts]
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue