mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 04:56:38 +02:00
🐛 Fix problem with shapes moving randomly
This commit is contained in:
parent
733b35dd53
commit
ff9b2090cf
1 changed files with 46 additions and 23 deletions
|
@ -30,6 +30,7 @@
|
||||||
(declare persist-changes)
|
(declare persist-changes)
|
||||||
(declare persist-synchronous-changes)
|
(declare persist-synchronous-changes)
|
||||||
(declare shapes-changes-persisted)
|
(declare shapes-changes-persisted)
|
||||||
|
(declare shapes-changes-persisted-finished)
|
||||||
(declare update-persistence-status)
|
(declare update-persistence-status)
|
||||||
|
|
||||||
;; --- Persistence
|
;; --- Persistence
|
||||||
|
@ -42,6 +43,7 @@
|
||||||
(log/debug :hint "initialize persistence")
|
(log/debug :hint "initialize persistence")
|
||||||
(let [stoper (rx/filter (ptk/type? ::initialize-persistence) stream)
|
(let [stoper (rx/filter (ptk/type? ::initialize-persistence) stream)
|
||||||
commits (l/atom [])
|
commits (l/atom [])
|
||||||
|
saving? (l/atom false)
|
||||||
|
|
||||||
local-file?
|
local-file?
|
||||||
#(as-> (:file-id %) event-file-id
|
#(as-> (:file-id %) event-file-id
|
||||||
|
@ -61,13 +63,15 @@
|
||||||
|
|
||||||
on-saving
|
on-saving
|
||||||
(fn []
|
(fn []
|
||||||
|
(reset! saving? true)
|
||||||
(st/emit! (update-persistence-status {:status :saving})))
|
(st/emit! (update-persistence-status {:status :saving})))
|
||||||
|
|
||||||
on-saved
|
on-saved
|
||||||
(fn []
|
(fn []
|
||||||
;; Disable reload stoper
|
;; Disable reload stoper
|
||||||
(swap! st/ongoing-tasks disj :workspace-change)
|
(swap! st/ongoing-tasks disj :workspace-change)
|
||||||
(st/emit! (update-persistence-status {:status :saved})))]
|
(st/emit! (update-persistence-status {:status :saved}))
|
||||||
|
(reset! saving? false))]
|
||||||
|
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(->> stream
|
(->> stream
|
||||||
|
@ -88,12 +92,15 @@
|
||||||
|
|
||||||
(->> (rx/from-atom commits)
|
(->> (rx/from-atom commits)
|
||||||
(rx/filter (complement empty?))
|
(rx/filter (complement empty?))
|
||||||
(rx/sample-when (rx/merge
|
(rx/sample-when
|
||||||
(rx/interval 5000)
|
(->> (rx/merge
|
||||||
(rx/filter #(= ::force-persist %) stream)
|
(rx/interval 5000)
|
||||||
(->> (rx/from-atom commits)
|
(rx/filter #(= ::force-persist %) stream)
|
||||||
(rx/filter (complement empty?))
|
(->> (rx/from-atom commits)
|
||||||
(rx/debounce 2000))))
|
(rx/filter (complement empty?))
|
||||||
|
(rx/debounce 2000)))
|
||||||
|
;; Not sample while saving so there are no race conditions
|
||||||
|
(rx/filter #(not @saving?))))
|
||||||
(rx/tap #(reset! commits []))
|
(rx/tap #(reset! commits []))
|
||||||
(rx/tap on-saving)
|
(rx/tap on-saving)
|
||||||
(rx/mapcat (fn [changes]
|
(rx/mapcat (fn [changes]
|
||||||
|
@ -101,9 +108,11 @@
|
||||||
;; next persistence before this one is
|
;; next persistence before this one is
|
||||||
;; finished.
|
;; finished.
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of (persist-changes file-id changes))
|
(->> (rx/of (persist-changes file-id changes commits))
|
||||||
|
(rx/observe-on :async))
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter (ptk/type? ::changes-persisted))
|
;; We wait for every change to be persisted
|
||||||
|
(rx/filter (ptk/type? ::shapes-changes-persisted-finished))
|
||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
(rx/tap on-saved)
|
(rx/tap on-saved)
|
||||||
(rx/ignore)))))
|
(rx/ignore)))))
|
||||||
|
@ -123,7 +132,7 @@
|
||||||
(log/debug :hint "finalize persistence: synchronous save loop")))))))))
|
(log/debug :hint "finalize persistence: synchronous save loop")))))))))
|
||||||
|
|
||||||
(defn persist-changes
|
(defn persist-changes
|
||||||
[file-id changes]
|
[file-id changes pending-commits]
|
||||||
(log/debug :hint "persist changes" :changes (count changes))
|
(log/debug :hint "persist changes" :changes (count changes))
|
||||||
(us/verify ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(ptk/reify ::persist-changes
|
(ptk/reify ::persist-changes
|
||||||
|
@ -150,20 +159,29 @@
|
||||||
(log/debug :hint "changes persisted" :lagged (count lagged))
|
(log/debug :hint "changes persisted" :lagged (count lagged))
|
||||||
(let [frame-updates
|
(let [frame-updates
|
||||||
(-> (group-by :page-id changes)
|
(-> (group-by :page-id changes)
|
||||||
(update-vals #(into #{} (mapcat :frames) %)))]
|
(update-vals #(into #{} (mapcat :frames) %)))
|
||||||
|
|
||||||
(rx/merge
|
commits
|
||||||
(->> (rx/from frame-updates)
|
(->> @pending-commits
|
||||||
(rx/mapcat (fn [[page-id frames]]
|
(map #(assoc % :revn (:revn file))))]
|
||||||
(->> frames (map #(vector page-id %)))))
|
|
||||||
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail (:id file) page-id frame-id))))
|
(rx/concat
|
||||||
(->> (rx/from lagged)
|
(rx/merge
|
||||||
(rx/merge-map (fn [{:keys [changes] :as entry}]
|
(->> (rx/from frame-updates)
|
||||||
(rx/merge
|
(rx/mapcat (fn [[page-id frames]]
|
||||||
(rx/from
|
(->> frames (map #(vector page-id %)))))
|
||||||
(for [[page-id changes] (group-by :page-id changes)]
|
(rx/map (fn [[page-id frame-id]] (dwt/update-thumbnail (:id file) page-id frame-id))))
|
||||||
(dch/update-indices page-id changes)))
|
|
||||||
(rx/of (shapes-changes-persisted file-id entry))))))))))
|
(->> (rx/from (concat lagged commits))
|
||||||
|
(rx/merge-map
|
||||||
|
(fn [{:keys [changes] :as entry}]
|
||||||
|
(rx/merge
|
||||||
|
(rx/from
|
||||||
|
(for [[page-id changes] (group-by :page-id changes)]
|
||||||
|
(dch/update-indices page-id changes)))
|
||||||
|
(rx/of (shapes-changes-persisted file-id entry)))))))
|
||||||
|
|
||||||
|
(rx/of (shapes-changes-persisted-finished))))))
|
||||||
(rx/catch (fn [cause]
|
(rx/catch (fn [cause]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(if (= :authentication (:type cause))
|
(if (= :authentication (:type cause))
|
||||||
|
@ -171,6 +189,11 @@
|
||||||
(rx/of (rt/assign-exception cause)))
|
(rx/of (rt/assign-exception cause)))
|
||||||
(rx/throw cause))))))))))
|
(rx/throw cause))))))))))
|
||||||
|
|
||||||
|
;; Event to be thrown after the changes have been persisted
|
||||||
|
(defn shapes-changes-persisted-finished
|
||||||
|
[]
|
||||||
|
(ptk/reify ::shapes-changes-persisted-finished))
|
||||||
|
|
||||||
(defn persist-synchronous-changes
|
(defn persist-synchronous-changes
|
||||||
[{:keys [file-id changes]}]
|
[{:keys [file-id changes]}]
|
||||||
(us/verify ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue