mirror of
https://github.com/penpot/penpot.git
synced 2025-07-29 14:07:14 +02:00
⚡ Add minor optimizations to shapes/bool component
This commit is contained in:
parent
c3c2d88245
commit
9993d357da
1 changed files with 23 additions and 21 deletions
|
@ -8,10 +8,9 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.shapes :as gsh]
|
[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.export :as use]
|
||||||
[app.main.ui.shapes.path :refer [path-shape]]
|
[app.main.ui.shapes.path :refer [path-shape]]
|
||||||
[app.util.object :as obj]
|
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(defn bool-shape
|
(defn bool-shape
|
||||||
|
@ -19,28 +18,31 @@
|
||||||
(mf/fnc bool-shape
|
(mf/fnc bool-shape
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [shape (obj/get props "shape")
|
(let [shape (unchecked-get props "shape")
|
||||||
childs (obj/get props "childs")
|
children (unchecked-get props "childs")
|
||||||
childs (use-equal-memo childs)
|
children (h/use-equal-memo children)
|
||||||
include-metadata? (mf/use-ctx use/include-metadata-ctx)
|
|
||||||
|
|
||||||
bool-content
|
metadata? (mf/use-ctx use/include-metadata-ctx)
|
||||||
(mf/use-memo
|
content (mf/with-memo [shape children]
|
||||||
(mf/deps shape childs)
|
(let [content (:bool-content shape)]
|
||||||
(fn []
|
(cond
|
||||||
(cond
|
(some? content)
|
||||||
(some? (:bool-content shape))
|
content
|
||||||
(:bool-content shape)
|
|
||||||
|
|
||||||
(some? childs)
|
(some? children)
|
||||||
(gsh/calc-bool-content shape childs))))]
|
(gsh/calc-bool-content shape children))))
|
||||||
|
|
||||||
|
shape (mf/with-memo [shape content]
|
||||||
|
(assoc shape :content content))]
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
(when (some? bool-content)
|
(when (some? content)
|
||||||
[:& path-shape {:shape (assoc shape :content bool-content)}])
|
[:& path-shape {:shape shape}])
|
||||||
|
|
||||||
(when include-metadata?
|
(when metadata?
|
||||||
|
;; FIXME: get children looks wrong
|
||||||
[:> "penpot:bool" {}
|
[:> "penpot:bool" {}
|
||||||
(for [item (->> (:shapes shape) (mapv #(get childs %)))]
|
(for [item (map #(get children %) (:shapes shape))]
|
||||||
[:& shape-wrapper {:shape item
|
[:& shape-wrapper
|
||||||
:key (dm/str (:id item))}])])])))
|
{:shape item
|
||||||
|
:key (dm/str (dm/get-prop item :id))}])])])))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue