0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

Remove posible race condition on page sync and history load.

This commit is contained in:
Andrey Antukh 2016-03-29 22:32:22 +03:00
parent 33fd84623f
commit f52b8796d1

View file

@ -88,20 +88,29 @@
;; --- Sync Page
(defrecord PageSynced [page]
rs/UpdateEvent
(-apply-update [this state]
(-> state
(assoc-in [:pages-by-id (:id page) :version] (:version page))
(stpr/assoc-page page))))
(defn- page-synced?
[event]
(instance? PageSynced event))
(defrecord SyncPage [id]
rs/WatchEvent
(-apply-watch [this state s]
(println "SyncPage")
(letfn [(on-success [{page :payload}]
(rx/of
#(assoc-in % [:pages-by-id id :version] (:version page))
#(stpr/assoc-page % page)))
(->PageSynced page))
(on-failure [e]
(uum/error (tr "errors.page-update"))
(rx/empty))]
(let [page (stpr/pack-page state id)]
(->> (rp/do :update/page page)
(rx/mapcat on-success)
(rx/map on-success)
(rx/catch on-failure))))))
(defn sync-page
@ -120,9 +129,13 @@
(let [page (get-in state [:pages-by-id id])]
(if (:history page)
(rx/empty)
(rx/of (sync-page id)
(fetch-page-history id)
(fetch-pinned-page-history id))))))
(rx/merge
(rx/of (sync-page id))
(->> (rx/filter page-synced? s)
(rx/take 1)
(rx/mapcat #(rx/of (fetch-page-history id)
(fetch-pinned-page-history id)))))))))
(defn update-page
[id]