Improved copy objects performance

This commit is contained in:
alonso.torres 2022-04-22 22:14:37 +02:00
parent 9492dd7856
commit 581c50b5ff
2 changed files with 26 additions and 29 deletions

View file

@ -502,3 +502,20 @@
(reduce process-shape (transient {}))
(persistent!))
persistent!)))
(defn selected-subtree
"Given a set of shapes, returns an objects subtree with the parents
of the selected items up to the root. Useful to calculate a partial z-index"
[objects selected]
(let [selected+parents
(into selected
(mapcat #(get-parent-ids objects %))
selected)
remove-children
(fn [shape]
(update shape :shapes #(filterv selected+parents %)))]
(-> (select-keys objects selected+parents)
(d/update-vals remove-children))))