mirror of
https://github.com/penpot/penpot.git
synced 2025-05-26 00:46:10 +02:00
♻️ Reorganize index management on worker code (#6477)
* ♻️ Factor index management out of app.worker.impl * 💄 Fix silly spacing * 💄 Lint
This commit is contained in:
parent
2635873b9a
commit
968ea56197
5 changed files with 41 additions and 29 deletions
|
@ -13,7 +13,7 @@
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.helpers :as dsh]
|
[app.main.data.helpers :as dsh]
|
||||||
[app.main.worker :as uw]
|
[app.main.worker :as mw]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
(->> (rx/from changes)
|
(->> (rx/from changes)
|
||||||
(rx/merge-map (fn [[page-id changes]]
|
(rx/merge-map (fn [[page-id changes]]
|
||||||
(log/debug :hint "update-indexes" :page-id page-id :changes (count changes))
|
(log/debug :hint "update-indexes" :page-id page-id :changes (count changes))
|
||||||
(uw/ask! {:cmd :update-page-index
|
(mw/ask! {:cmd :index/update-page-index
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:changes changes})))
|
:changes changes})))
|
||||||
(rx/catch (fn [cause]
|
(rx/catch (fn [cause]
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.main.router :as rt]
|
[app.main.router :as rt]
|
||||||
[app.main.streams :as ms]
|
[app.main.streams :as ms]
|
||||||
[app.main.worker :as uw]
|
[app.main.worker :as mw]
|
||||||
[app.render-wasm :as wasm]
|
[app.render-wasm :as wasm]
|
||||||
[app.render-wasm.api :as api]
|
[app.render-wasm.api :as api]
|
||||||
[app.util.code-gen.style-css :as css]
|
[app.util.code-gen.style-css :as css]
|
||||||
|
@ -165,7 +165,7 @@
|
||||||
(rx/mapcat
|
(rx/mapcat
|
||||||
(fn [[id page]]
|
(fn [[id page]]
|
||||||
(let [page (update page :objects ctst/start-page-index)]
|
(let [page (update page :objects ctst/start-page-index)]
|
||||||
(->> (uw/ask! {:cmd :initialize-page-index :page page})
|
(->> (mw/ask! {:cmd :index/initialize-page-index :page page})
|
||||||
(rx/map (fn [_] [id page]))))))
|
(rx/map (fn [_] [id page]))))))
|
||||||
(rx/reduce conj {})
|
(rx/reduce conj {})
|
||||||
(rx/map (fn [pages-index]
|
(rx/map (fn [pages-index]
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
[app.worker.export]
|
[app.worker.export]
|
||||||
[app.worker.impl :as impl]
|
[app.worker.impl :as impl]
|
||||||
[app.worker.import]
|
[app.worker.import]
|
||||||
|
[app.worker.index]
|
||||||
[app.worker.messages :as wm]
|
[app.worker.messages :as wm]
|
||||||
[app.worker.selection]
|
[app.worker.selection]
|
||||||
[app.worker.snaps]
|
[app.worker.snaps]
|
||||||
|
|
|
@ -5,19 +5,15 @@
|
||||||
;; Copyright (c) KALEIDOS INC
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
(ns app.worker.impl
|
(ns app.worker.impl
|
||||||
|
"Dispatcher for messages received from the main thread."
|
||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
|
||||||
[app.common.files.changes :as ch]
|
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.config :as cf]
|
[app.config :as cf]))
|
||||||
[okulary.core :as l]))
|
|
||||||
|
|
||||||
(log/set-level! :info)
|
(log/set-level! :info)
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
(defonce state (l/atom {:pages-index {}}))
|
|
||||||
|
|
||||||
;; --- Handler
|
;; --- Handler
|
||||||
|
|
||||||
(defmulti handler :cmd)
|
(defmulti handler :cmd)
|
||||||
|
@ -30,25 +26,6 @@
|
||||||
[message]
|
[message]
|
||||||
message)
|
message)
|
||||||
|
|
||||||
(defmethod handler :initialize-page-index
|
|
||||||
[{:keys [page] :as message}]
|
|
||||||
(swap! state update :pages-index assoc (:id page) page)
|
|
||||||
(handler (assoc message :cmd :selection/initialize-page-index))
|
|
||||||
(handler (assoc message :cmd :snaps/initialize-page-index)))
|
|
||||||
|
|
||||||
(defmethod handler :update-page-index
|
|
||||||
[{:keys [page-id changes] :as message}]
|
|
||||||
|
|
||||||
(let [old-page (dm/get-in @state [:pages-index page-id])
|
|
||||||
new-page (-> state
|
|
||||||
(swap! ch/process-changes changes false)
|
|
||||||
(dm/get-in [:pages-index page-id]))
|
|
||||||
message (assoc message
|
|
||||||
:old-page old-page
|
|
||||||
:new-page new-page)]
|
|
||||||
(handler (assoc message :cmd :selection/update-page-index))
|
|
||||||
(handler (assoc message :cmd :snaps/update-page-index))))
|
|
||||||
|
|
||||||
(defmethod handler :configure
|
(defmethod handler :configure
|
||||||
[{:keys [config]}]
|
[{:keys [config]}]
|
||||||
(log/info :hint "configure worker" :keys (keys config))
|
(log/info :hint "configure worker" :keys (keys config))
|
||||||
|
|
34
frontend/src/app/worker/index.cljs
Normal file
34
frontend/src/app/worker/index.cljs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.worker.index
|
||||||
|
"Page index management within the worker."
|
||||||
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.files.changes :as ch]
|
||||||
|
[app.worker.impl :as impl]
|
||||||
|
[okulary.core :as l]))
|
||||||
|
|
||||||
|
(defonce state (l/atom {:pages-index {}}))
|
||||||
|
|
||||||
|
(defmethod impl/handler :index/initialize-page-index
|
||||||
|
[{:keys [page] :as message}]
|
||||||
|
(swap! state update :pages-index assoc (:id page) page)
|
||||||
|
(impl/handler (assoc message :cmd :selection/initialize-page-index))
|
||||||
|
(impl/handler (assoc message :cmd :snaps/initialize-page-index)))
|
||||||
|
|
||||||
|
(defmethod impl/handler :index/update-page-index
|
||||||
|
[{:keys [page-id changes] :as message}]
|
||||||
|
|
||||||
|
(let [old-page (dm/get-in @state [:pages-index page-id])
|
||||||
|
new-page (-> state
|
||||||
|
(swap! ch/process-changes changes false)
|
||||||
|
(dm/get-in [:pages-index page-id]))
|
||||||
|
message (assoc message
|
||||||
|
:old-page old-page
|
||||||
|
:new-page new-page)]
|
||||||
|
(impl/handler (assoc message :cmd :selection/update-page-index))
|
||||||
|
(impl/handler (assoc message :cmd :snaps/update-page-index))))
|
Loading…
Add table
Add a link
Reference in a new issue