mirror of
https://github.com/penpot/penpot.git
synced 2025-02-18 21:06:11 -05:00
⚡ Memoize shapes
This commit is contained in:
parent
0b6c2df5b6
commit
91f60000b3
3 changed files with 26 additions and 3 deletions
|
@ -12,7 +12,8 @@
|
||||||
(defn generic-wrapper-factory
|
(defn generic-wrapper-factory
|
||||||
[component]
|
[component]
|
||||||
(mf/fnc generic-wrapper
|
(mf/fnc generic-wrapper
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap [#(mf/memo' % (mf/check-props ["shape"]))]
|
||||||
|
::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [shape (unchecked-get props "shape")]
|
(let [shape (unchecked-get props "shape")]
|
||||||
[:> shape-container {:shape shape}
|
[:> shape-container {:shape shape}
|
||||||
|
|
|
@ -28,6 +28,28 @@
|
||||||
(contains? (:selected local) id)))]
|
(contains? (:selected local) id)))]
|
||||||
(l/derived check-moving refs/workspace-local)))
|
(l/derived check-moving refs/workspace-local)))
|
||||||
|
|
||||||
|
(defn check-props
|
||||||
|
([props] (check-props props =))
|
||||||
|
([props eqfn?]
|
||||||
|
(fn [np op]
|
||||||
|
(every? #(eqfn? (unchecked-get np %)
|
||||||
|
(unchecked-get op %))
|
||||||
|
props))))
|
||||||
|
|
||||||
|
(defn check-frame-props
|
||||||
|
"Checks for changes in the props of a frame"
|
||||||
|
[new-props old-props]
|
||||||
|
(let [new-shape (unchecked-get new-props "shape")
|
||||||
|
old-shape (unchecked-get old-props "shape")
|
||||||
|
|
||||||
|
new-objects (unchecked-get new-props "objects")
|
||||||
|
old-objects (unchecked-get old-props "objects")
|
||||||
|
|
||||||
|
new-children (->> new-shape :shapes (mapv #(get new-objects %)))
|
||||||
|
old-children (->> old-shape :shapes (mapv #(get old-objects %)))]
|
||||||
|
(and (= new-shape old-shape)
|
||||||
|
(= new-children old-children))))
|
||||||
|
|
||||||
;; This custom deffered don't deffer rendering when ghost rendering is
|
;; This custom deffered don't deffer rendering when ghost rendering is
|
||||||
;; used.
|
;; used.
|
||||||
(defn custom-deferred
|
(defn custom-deferred
|
||||||
|
@ -48,7 +70,7 @@
|
||||||
[shape-wrapper]
|
[shape-wrapper]
|
||||||
(let [frame-shape (frame/frame-shape shape-wrapper)]
|
(let [frame-shape (frame/frame-shape shape-wrapper)]
|
||||||
(mf/fnc frame-wrapper
|
(mf/fnc frame-wrapper
|
||||||
{::mf/wrap [#(mf/memo' % (mf/check-props ["shape" "objects"])) custom-deferred]
|
{::mf/wrap [#(mf/memo' % check-frame-props) custom-deferred]
|
||||||
::mf/wrap-props false}
|
::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [shape (unchecked-get props "shape")
|
(let [shape (unchecked-get props "shape")
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
[shape-wrapper]
|
[shape-wrapper]
|
||||||
(let [group-shape (group/group-shape shape-wrapper)]
|
(let [group-shape (group/group-shape shape-wrapper)]
|
||||||
(mf/fnc group-wrapper
|
(mf/fnc group-wrapper
|
||||||
{::mf/wrap [#(mf/memo' % (mf/check-props ["shape" "frame"]))]
|
{::mf/wrap [#(mf/memo' % (mf/check-props ["shape"]))]
|
||||||
::mf/wrap-props false}
|
::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [shape (unchecked-get props "shape")
|
(let [shape (unchecked-get props "shape")
|
||||||
|
|
Loading…
Add table
Reference in a new issue