mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 18:16:11 +02: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)]
|
(let [page-id (:current-page-id state)]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(when (some :page-id changes)
|
(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))
|
(when (and save-undo? (seq undo-changes))
|
||||||
(let [entry {:undo-changes undo-changes
|
(let [entry {:undo-changes undo-changes
|
||||||
|
@ -174,14 +174,13 @@
|
||||||
(rx/map (constantly ::index-initialized)))))))
|
(rx/map (constantly ::index-initialized)))))))
|
||||||
|
|
||||||
(defn update-indices
|
(defn update-indices
|
||||||
[page-id]
|
[page-id changes]
|
||||||
(ptk/reify ::update-indices
|
(ptk/reify ::update-indices
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state stream]
|
(effect [_ state stream]
|
||||||
(let [objects (lookup-page-objects state page-id)]
|
|
||||||
(uw/ask! {:cmd :update-page-indices
|
(uw/ask! {:cmd :update-page-indices
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:objects objects})))))
|
:changes changes}))))
|
||||||
|
|
||||||
;; --- Common Helpers & Events
|
;; --- Common Helpers & Events
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of (dwp/shapes-changes-persisted file-id msg))
|
(rx/of (dwp/shapes-changes-persisted file-id msg))
|
||||||
(when (seq page-ids)
|
(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/def ::library-change-event
|
||||||
(s/keys :req-un [::type
|
(s/keys :req-un [::type
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
(ns app.worker.impl
|
(ns app.worker.impl
|
||||||
(:require
|
(:require
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
[app.util.transit :as t]))
|
[app.util.transit :as t]
|
||||||
|
[app.common.pages.changes :as ch]))
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
|
(defonce state (l/atom {:pages-index {}}))
|
||||||
|
|
||||||
;; --- Handler
|
;; --- Handler
|
||||||
|
|
||||||
(defmulti handler :cmd)
|
(defmulti handler :cmd)
|
||||||
|
@ -24,15 +27,23 @@
|
||||||
message)
|
message)
|
||||||
|
|
||||||
(defmethod handler :initialize-indices
|
(defmethod handler :initialize-indices
|
||||||
[message]
|
[{:keys [data] :as message}]
|
||||||
|
|
||||||
|
(reset! state data)
|
||||||
|
|
||||||
(handler (-> message
|
(handler (-> message
|
||||||
(assoc :cmd :selection/initialize-index)))
|
(assoc :cmd :selection/initialize-index)))
|
||||||
(handler (-> message
|
(handler (-> message
|
||||||
(assoc :cmd :snaps/initialize-index))))
|
(assoc :cmd :snaps/initialize-index))))
|
||||||
|
|
||||||
(defmethod handler :update-page-indices
|
(defmethod handler :update-page-indices
|
||||||
[message]
|
[{: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
|
(handler (-> message
|
||||||
(assoc :cmd :selection/update-index)))
|
(assoc :cmd :selection/update-index)))
|
||||||
(handler (-> message
|
(handler (-> message
|
||||||
(assoc :cmd :snaps/update-index))))
|
(assoc :cmd :snaps/update-index)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue