mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 17:00:36 -05:00
⚡ Reduce unnecesary lookups on get-frame-by-position fn
This commit is contained in:
parent
6b3fa31d68
commit
b7eb20dc44
5 changed files with 27 additions and 23 deletions
|
@ -239,10 +239,10 @@
|
||||||
unames (volatile! (cfh/get-used-names objects))
|
unames (volatile! (cfh/get-used-names objects))
|
||||||
|
|
||||||
frame-id (or force-frame-id
|
frame-id (or force-frame-id
|
||||||
(ctst/frame-id-by-position objects
|
(ctst/get-frame-id-by-position objects
|
||||||
(gpt/add orig-pos delta)
|
(gpt/add orig-pos delta)
|
||||||
{:skip-components? true
|
{:skip-components? true
|
||||||
:bottom-frames? true}))
|
:bottom-frames? true}))
|
||||||
frame-ids-map (volatile! {})
|
frame-ids-map (volatile! {})
|
||||||
|
|
||||||
update-new-shape
|
update-new-shape
|
||||||
|
@ -315,4 +315,4 @@
|
||||||
parent (get objects parent-id)]
|
parent (get objects parent-id)]
|
||||||
(if (= parent-id uuid/zero)
|
(if (= parent-id uuid/zero)
|
||||||
current-top
|
current-top
|
||||||
(get-top-instance objects parent current-top))))
|
(get-top-instance objects parent current-top))))
|
||||||
|
|
|
@ -256,23 +256,27 @@
|
||||||
-1))))
|
-1))))
|
||||||
items)))
|
items)))
|
||||||
|
|
||||||
(defn frame-id-by-position
|
(defn get-frame-by-position
|
||||||
([objects position] (frame-id-by-position objects position nil))
|
([objects position]
|
||||||
([objects position options]
|
(get-frame-by-position objects position nil))
|
||||||
(assert (gpt/point? position))
|
|
||||||
(let [sort-with-options (fn [objects ids]
|
|
||||||
(sort-z-index objects ids options))
|
|
||||||
top-frame
|
|
||||||
(->> (get-frames-ids objects options)
|
|
||||||
(sort-with-options objects)
|
|
||||||
(d/seek #(and position (gsh/has-point? (get objects %) position))))]
|
|
||||||
(or top-frame uuid/zero))))
|
|
||||||
|
|
||||||
(defn frame-by-position
|
|
||||||
([objects position] (frame-by-position objects position nil))
|
|
||||||
([objects position options]
|
([objects position options]
|
||||||
(let [frame-id (frame-id-by-position objects position options)]
|
(dm/assert!
|
||||||
(get objects frame-id))))
|
"expected a point"
|
||||||
|
(gpt/point? position))
|
||||||
|
|
||||||
|
(let [frames (get-frames objects options)
|
||||||
|
frames (sort-z-index-objects objects frames options)]
|
||||||
|
(or (d/seek #(and ^boolean (some? position)
|
||||||
|
^boolean (gsh/has-point? % position))
|
||||||
|
frames)
|
||||||
|
(get objects uuid/zero)))))
|
||||||
|
|
||||||
|
(defn get-frame-id-by-position
|
||||||
|
([objects position] (get-frame-id-by-position objects position nil))
|
||||||
|
([objects position options]
|
||||||
|
(when-let [frame (get-frame-by-position objects position options)]
|
||||||
|
(dm/get-prop frame :id))))
|
||||||
|
|
||||||
(defn get-frames-by-position
|
(defn get-frames-by-position
|
||||||
([objects position] (get-frames-by-position objects position nil))
|
([objects position] (get-frames-by-position objects position nil))
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame-id (ctst/frame-id-by-position objects (:position params))
|
frame-id (ctst/get-frame-id-by-position objects (:position params))
|
||||||
params (assoc params :frame-id frame-id)]
|
params (assoc params :frame-id frame-id)]
|
||||||
(->> (rp/cmd! :create-comment-thread params)
|
(->> (rp/cmd! :create-comment-thread params)
|
||||||
(rx/mapcat #(rp/cmd! :get-comment-thread {:file-id (:file-id %) :id (:id %)}))
|
(rx/mapcat #(rp/cmd! :get-comment-thread {:file-id (:file-id %) :id (:id %)}))
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
page-id (:id page)
|
page-id (:id page)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
new-frame-id (if (nil? frame-id)
|
new-frame-id (if (nil? frame-id)
|
||||||
(ctst/frame-id-by-position objects (gpt/point new-x new-y))
|
(ctst/get-frame-id-by-position objects (gpt/point new-x new-y))
|
||||||
(:frame-id thread))
|
(:frame-id thread))
|
||||||
thread (assoc thread
|
thread (assoc thread
|
||||||
:position (gpt/point new-x new-y)
|
:position (gpt/point new-x new-y)
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
from-frame-id (if (cph/frame-shape? from-shape)
|
from-frame-id (if (cph/frame-shape? from-shape)
|
||||||
from-id (:frame-id from-shape))
|
from-id (:frame-id from-shape))
|
||||||
|
|
||||||
target-frame (ctst/frame-by-position objects position)]
|
target-frame (ctst/get-frame-by-position objects position)]
|
||||||
|
|
||||||
(when (and (not= (:id target-frame) uuid/zero)
|
(when (and (not= (:id target-frame) uuid/zero)
|
||||||
(not= (:id target-frame) from-frame-id))
|
(not= (:id target-frame) from-frame-id))
|
||||||
|
|
Loading…
Reference in a new issue