From 9993d357da97e318425d4e20ad812a66fc0e5133 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 5 Sep 2023 23:17:35 +0200 Subject: [PATCH] :zap: Add minor optimizations to shapes/bool component --- frontend/src/app/main/ui/shapes/bool.cljs | 44 ++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/frontend/src/app/main/ui/shapes/bool.cljs b/frontend/src/app/main/ui/shapes/bool.cljs index 1eee71753d..7f378244f1 100644 --- a/frontend/src/app/main/ui/shapes/bool.cljs +++ b/frontend/src/app/main/ui/shapes/bool.cljs @@ -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))}])])])))