mirror of
https://github.com/penpot/penpot.git
synced 2025-04-16 08:51:32 -05:00
✨ Improved performance in workers
This commit is contained in:
parent
385c7274a3
commit
44eb961c27
3 changed files with 24 additions and 14 deletions
|
@ -108,7 +108,7 @@
|
|||
(let [page-id (:current-page-id state)]
|
||||
(rx/concat
|
||||
(when (some :page-id changes)
|
||||
(rx/of (update-indices page-id)))
|
||||
(rx/of (update-indices page-id changes)))
|
||||
|
||||
(when (and save-undo? (seq undo-changes))
|
||||
(let [entry {:undo-changes undo-changes
|
||||
|
@ -174,14 +174,13 @@
|
|||
(rx/map (constantly ::index-initialized)))))))
|
||||
|
||||
(defn update-indices
|
||||
[page-id]
|
||||
[page-id changes]
|
||||
(ptk/reify ::update-indices
|
||||
ptk/EffectEvent
|
||||
(effect [_ state stream]
|
||||
(let [objects (lookup-page-objects state page-id)]
|
||||
(uw/ask! {:cmd :update-page-indices
|
||||
:page-id page-id
|
||||
:objects objects})))))
|
||||
(uw/ask! {:cmd :update-page-indices
|
||||
:page-id page-id
|
||||
:changes changes}))))
|
||||
|
||||
;; --- Common Helpers & Events
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@
|
|||
(rx/merge
|
||||
(rx/of (dwp/shapes-changes-persisted file-id msg))
|
||||
(when (seq page-ids)
|
||||
(rx/from (map dwc/update-indices page-ids))))))))
|
||||
(rx/from (map dwc/update-indices page-ids changes))))))))
|
||||
|
||||
(s/def ::library-change-event
|
||||
(s/keys :req-un [::type
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
(ns app.worker.impl
|
||||
(:require
|
||||
[okulary.core :as l]
|
||||
[app.util.transit :as t]))
|
||||
[app.util.transit :as t]
|
||||
[app.common.pages.changes :as ch]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
(defonce state (l/atom {:pages-index {}}))
|
||||
|
||||
;; --- Handler
|
||||
|
||||
(defmulti handler :cmd)
|
||||
|
@ -24,15 +27,23 @@
|
|||
message)
|
||||
|
||||
(defmethod handler :initialize-indices
|
||||
[message]
|
||||
[{:keys [data] :as message}]
|
||||
|
||||
(reset! state data)
|
||||
|
||||
(handler (-> message
|
||||
(assoc :cmd :selection/initialize-index)))
|
||||
(handler (-> message
|
||||
(assoc :cmd :snaps/initialize-index))))
|
||||
|
||||
(defmethod handler :update-page-indices
|
||||
[message]
|
||||
(handler (-> message
|
||||
(assoc :cmd :selection/update-index)))
|
||||
(handler (-> message
|
||||
(assoc :cmd :snaps/update-index))))
|
||||
[{:keys [page-id changes] :as message}]
|
||||
|
||||
(swap! state ch/process-changes changes false)
|
||||
|
||||
(let [objects (get-in @state [:pages-index page-id :objects])
|
||||
message (assoc message :objects objects)]
|
||||
(handler (-> message
|
||||
(assoc :cmd :selection/update-index)))
|
||||
(handler (-> message
|
||||
(assoc :cmd :snaps/update-index)))))
|
||||
|
|
Loading…
Add table
Reference in a new issue