0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00

🐛 Fix unexpected operation ordering.

This commit is contained in:
Andrey Antukh 2020-01-28 12:48:09 +01:00
parent 75b64b71bf
commit 590b68aa29
3 changed files with 12 additions and 31 deletions

View file

@ -181,7 +181,8 @@
"select s.id, s.changes
from project_page_snapshots as s
where s.page_id = $1
and s.version > $2")
and s.version > $2
order by s.created_at asc")
(defn- retrieve-lagged-changes
[conn snapshot params]

View file

@ -62,7 +62,7 @@
;; --- Helpers
(defn unpack-page
[state {:keys [id data metadata] :as page}]
[state {:keys [id data] :as page}]
(-> state
(update :pages assoc id (dissoc page :data))
(update :pages-data assoc id data)))

View file

@ -60,7 +60,6 @@
(declare handle-page-snapshot)
(declare shapes-changes-commited)
(declare commit-changes)
(declare commit-batched-changes)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Websockets Events
@ -245,7 +244,6 @@
(assoc state
:workspace-local workspace-default
:workspace-data data
:workspace-data-prev data
:workspace-page page)))
ptk/WatchEvent
@ -274,8 +272,9 @@
(ptk/reify ::diff-and-commit-changes
ptk/WatchEvent
(watch [_ state stream]
(let [curr (get-in state [:workspace-data :shapes-by-id])
prev (get-in state [:workspace-data-prev :shapes-by-id])
(let [pid (get-in state [:workspace-page :id])
curr (get-in state [:workspace-data :shapes-by-id])
prev (get-in state [:pages-data pid :shapes-by-id])
diff (d/diff-maps prev curr)
changes (loop [scs (rest diff)
@ -959,9 +958,7 @@
(update [_ state]
(let [pid (get-in state [:workspace-page :id])
data (get-in state [:pages-data pid])]
(-> state
(update-in [:pages-data pid] cp/process-changes changes)
(assoc :workspace-data-prev (:workspace-data state)))))
(update-in state [:pages-data pid] cp/process-changes changes)))
ptk/WatchEvent
(watch [_ state stream]
@ -972,21 +969,6 @@
(->> (rp/mutation :update-project-page params)
(rx/map shapes-changes-commited))))))
(def commit-batched-changes
(ptk/reify ::commit-batched-changes
ptk/UpdateEvent
(update [_ state]
(let [pid (get-in state [:workspace-page :id])
data (get-in state [:pages-data pid])
changes (::batched-changes state)]
(update-in state [:pages-data pid] cp/process-changes changes)))
ptk/WatchEvent
(watch [_ state stream]
(let [changes (::batched-changes state)]
(rx/of #(dissoc % ::batched-changes)
(commit-changes changes))))))
(s/def ::shapes-changes-commited
(s/keys :req-un [::page-id ::version ::cp/changes]))
@ -996,13 +978,11 @@
(ptk/reify ::shapes-changes-commited
ptk/UpdateEvent
(update [_ state]
(let [sid (:session-id state)
changes (remove #(= sid (:session-id %)) changes)]
(-> state
(assoc-in [:workspace-page :version] version)
(assoc-in [:pages page-id :version] version)
(update-in [:pages-data page-id] cp/process-changes changes)
(update :workspace-data cp/process-changes changes))))))
(-> state
(assoc-in [:workspace-page :version] version)
(assoc-in [:pages page-id :version] version)
(update-in [:pages-data page-id] cp/process-changes changes)
(update :workspace-data cp/process-changes changes)))))
;; --- Start shape "edition mode"