0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-25 08:16:49 -05:00

Add minor optimizations to shapes/bool component

This commit is contained in:
Andrey Antukh 2023-09-05 23:17:35 +02:00
parent c3c2d88245
commit 9993d357da

View file

@ -8,10 +8,9 @@
(:require
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.main.ui.hooks :refer [use-equal-memo]]
[app.main.ui.hooks :as h]
[app.main.ui.shapes.export :as use]
[app.main.ui.shapes.path :refer [path-shape]]
[app.util.object :as obj]
[rumext.v2 :as mf]))
(defn bool-shape
@ -19,28 +18,31 @@
(mf/fnc bool-shape
{::mf/wrap-props false}
[props]
(let [shape (obj/get props "shape")
childs (obj/get props "childs")
childs (use-equal-memo childs)
include-metadata? (mf/use-ctx use/include-metadata-ctx)
(let [shape (unchecked-get props "shape")
children (unchecked-get props "childs")
children (h/use-equal-memo children)
bool-content
(mf/use-memo
(mf/deps shape childs)
(fn []
(cond
(some? (:bool-content shape))
(:bool-content shape)
metadata? (mf/use-ctx use/include-metadata-ctx)
content (mf/with-memo [shape children]
(let [content (:bool-content shape)]
(cond
(some? content)
content
(some? childs)
(gsh/calc-bool-content shape childs))))]
(some? children)
(gsh/calc-bool-content shape children))))
shape (mf/with-memo [shape content]
(assoc shape :content content))]
[:*
(when (some? bool-content)
[:& path-shape {:shape (assoc shape :content bool-content)}])
(when (some? content)
[:& path-shape {:shape shape}])
(when include-metadata?
(when metadata?
;; FIXME: get children looks wrong
[:> "penpot:bool" {}
(for [item (->> (:shapes shape) (mapv #(get childs %)))]
[:& shape-wrapper {:shape item
:key (dm/str (:id item))}])])])))
(for [item (map #(get children %) (:shapes shape))]
[:& shape-wrapper
{:shape item
:key (dm/str (dm/get-prop item :id))}])])])))