mirror of
https://github.com/penpot/penpot.git
synced 2025-07-31 11:48:32 +02:00
🎉 Introduce async (batched) shapes changes commit event.
This commit is contained in:
parent
8e228be5a0
commit
a2dc0a5f56
1 changed files with 38 additions and 10 deletions
|
@ -117,11 +117,7 @@
|
||||||
|
|
||||||
(defn interrupt? [e] (= e :interrupt))
|
(defn interrupt? [e] (= e :interrupt))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; --- Declarations
|
||||||
;; Websockets Events
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
;; --- Initialize WebSocket
|
|
||||||
|
|
||||||
(declare fetch-users)
|
(declare fetch-users)
|
||||||
(declare handle-who)
|
(declare handle-who)
|
||||||
|
@ -129,6 +125,15 @@
|
||||||
(declare handle-pointer-send)
|
(declare handle-pointer-send)
|
||||||
(declare handle-page-snapshot)
|
(declare handle-page-snapshot)
|
||||||
(declare shapes-changes-commited)
|
(declare shapes-changes-commited)
|
||||||
|
(declare commit-shapes-changes)
|
||||||
|
(declare async-commit-shapes-changes)
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Websockets Events
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
;; --- Initialize WebSocket
|
||||||
|
|
||||||
|
|
||||||
(s/def ::type keyword?)
|
(s/def ::type keyword?)
|
||||||
(s/def ::message
|
(s/def ::message
|
||||||
|
@ -293,7 +298,7 @@
|
||||||
[file-id page-id]
|
[file-id page-id]
|
||||||
(s/assert ::us/uuid file-id)
|
(s/assert ::us/uuid file-id)
|
||||||
(s/assert ::us/uuid page-id)
|
(s/assert ::us/uuid page-id)
|
||||||
(ptk/reify ::initialized
|
(ptk/reify ::finalize
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(dissoc state
|
(dissoc state
|
||||||
|
@ -309,7 +314,25 @@
|
||||||
data (get-in state [:pages-data page-id])]
|
data (get-in state [:pages-data page-id])]
|
||||||
(assoc state
|
(assoc state
|
||||||
:workspace-data data
|
:workspace-data data
|
||||||
:workspace-page page)))))
|
:workspace-page page)))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [stoper (rx/filter #(or (ptk/type? ::finalize %)
|
||||||
|
(ptk/type? ::initialize-page %))
|
||||||
|
stream)
|
||||||
|
notifier (->> stream
|
||||||
|
(rx/filter (ptk/type? ::async-commit-shapes-changes))
|
||||||
|
(rx/debounce 500))]
|
||||||
|
(->> stream
|
||||||
|
(rx/filter (ptk/type? ::async-commit-shapes-changes))
|
||||||
|
(rx/map deref)
|
||||||
|
(rx/mapcat identity)
|
||||||
|
(rx/buffer-until notifier)
|
||||||
|
(rx/map vec)
|
||||||
|
(rx/map commit-shapes-changes)
|
||||||
|
(rx/take-until stoper)
|
||||||
|
(rx/finalize #(prn "FINALIZE" %)))))))
|
||||||
|
|
||||||
;; --- Fetch Workspace Users
|
;; --- Fetch Workspace Users
|
||||||
|
|
||||||
|
@ -588,7 +611,6 @@
|
||||||
(update-in $ [:workspace-data :shapes] conj id))
|
(update-in $ [:workspace-data :shapes] conj id))
|
||||||
(assoc-in $ [:workspace-data :shapes-by-id id] shape))))
|
(assoc-in $ [:workspace-data :shapes-by-id id] shape))))
|
||||||
|
|
||||||
(declare commit-shapes-changes)
|
|
||||||
(declare select-shape)
|
(declare select-shape)
|
||||||
(declare recalculate-shape-canvas-relation)
|
(declare recalculate-shape-canvas-relation)
|
||||||
|
|
||||||
|
@ -741,7 +763,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [change (::tmp-change state)]
|
(let [change (::tmp-change state)]
|
||||||
(rx/of (commit-shapes-changes [change])
|
(rx/of (async-commit-shapes-changes [change])
|
||||||
#(dissoc state ::tmp-change))))))
|
#(dissoc state ::tmp-change))))))
|
||||||
|
|
||||||
;; --- Update Selected Shapes attrs
|
;; --- Update Selected Shapes attrs
|
||||||
|
@ -1006,7 +1028,6 @@
|
||||||
[operations]
|
[operations]
|
||||||
(s/assert ::cp/operations operations)
|
(s/assert ::cp/operations operations)
|
||||||
(ptk/reify ::commit-shapes-changes
|
(ptk/reify ::commit-shapes-changes
|
||||||
;; Commits the just performed changes to root pages-data
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [pid (get-in state [:workspace-local :page-id])
|
(let [pid (get-in state [:workspace-local :page-id])
|
||||||
|
@ -1022,6 +1043,13 @@
|
||||||
(->> (rp/mutation :update-project-page params)
|
(->> (rp/mutation :update-project-page params)
|
||||||
(rx/map shapes-changes-commited))))))
|
(rx/map shapes-changes-commited))))))
|
||||||
|
|
||||||
|
(defn async-commit-shapes-changes
|
||||||
|
[operations]
|
||||||
|
(s/assert ::cp/operations operations)
|
||||||
|
(ptk/reify ::async-commit-shapes-changes
|
||||||
|
cljs.core/IDeref
|
||||||
|
(-deref [_] operations)))
|
||||||
|
|
||||||
(s/def ::shapes-changes-commited
|
(s/def ::shapes-changes-commited
|
||||||
(s/keys :req-un [::page-id ::version ::cp/operations]))
|
(s/keys :req-un [::page-id ::version ::cp/operations]))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue