mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
⚡ Debounce update position-data event
This commit is contained in:
parent
6ad591eb23
commit
2b9badfd4e
2 changed files with 45 additions and 8 deletions
|
@ -13,6 +13,7 @@
|
|||
[app.common.math :as mth]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
|
@ -379,3 +380,45 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(d/dissoc-in state [:workspace-text-modifier id]))))
|
||||
|
||||
(defn commit-position-data
|
||||
[]
|
||||
(ptk/reify ::commit-position-data
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [position-data (::update-position-data state)]
|
||||
(rx/concat
|
||||
(rx/of (dch/update-shapes
|
||||
(keys position-data)
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(assoc :position-data (get position-data (:id shape))))
|
||||
)
|
||||
{:save-undo? false :reg-objects? false}))
|
||||
(rx/of (fn [state]
|
||||
(dissoc state ::update-position-data-debounce ::update-position-data))))))))
|
||||
|
||||
(defn update-position-data
|
||||
[id position-data]
|
||||
|
||||
(let [start (uuid/next)]
|
||||
(ptk/reify ::update-position-data
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(if (nil? (::update-position-data-debounce state))
|
||||
(assoc state ::update-position-data-debounce start)
|
||||
(assoc-in state [::update-position-data id] position-data)))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(if (= (::update-position-data-debounce state) start)
|
||||
(let [stopper (->> stream (rx/filter (ptk/type? :app.main.data.workspace/finalize)))]
|
||||
(rx/merge
|
||||
(->> stream
|
||||
(rx/filter (ptk/type? ::update-position-data))
|
||||
(rx/debounce 50)
|
||||
(rx/take 1)
|
||||
(rx/map #(commit-position-data))
|
||||
(rx/take-until stopper))
|
||||
(rx/of (update-position-data id position-data))))
|
||||
(rx/empty))))))
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
[app.common.math :as mth]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.text :as txt]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.fonts :as fonts]
|
||||
[app.main.refs :as refs]
|
||||
|
@ -41,7 +40,7 @@
|
|||
(assoc :content (attrs/merge content editor-content)))))
|
||||
|
||||
(defn- update-text-shape
|
||||
[{:keys [grow-type id]} node]
|
||||
[{:keys [grow-type id] :as shape} node]
|
||||
;; Check if we need to update the size because it's auto-width or auto-height
|
||||
(when (contains? #{:auto-height :auto-width} grow-type)
|
||||
(let [{:keys [width height]}
|
||||
|
@ -54,12 +53,7 @@
|
|||
|
||||
;; Update the position-data of every text fragment
|
||||
(let [position-data (utp/calc-position-data node)]
|
||||
(st/emit! (dch/update-shapes
|
||||
[id]
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(assoc :position-data position-data)))
|
||||
{:save-undo? false}))))
|
||||
(st/emit! (dwt/update-position-data id position-data))))
|
||||
|
||||
(defn- update-text-modifier
|
||||
[{:keys [grow-type id]} node]
|
||||
|
|
Loading…
Add table
Reference in a new issue