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 ;; --- 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] (defrecord SyncPage [id]
rs/WatchEvent rs/WatchEvent
(-apply-watch [this state s] (-apply-watch [this state s]
(println "SyncPage") (println "SyncPage")
(letfn [(on-success [{page :payload}] (letfn [(on-success [{page :payload}]
(rx/of (->PageSynced page))
#(assoc-in % [:pages-by-id id :version] (:version page))
#(stpr/assoc-page % page)))
(on-failure [e] (on-failure [e]
(uum/error (tr "errors.page-update")) (uum/error (tr "errors.page-update"))
(rx/empty))] (rx/empty))]
(let [page (stpr/pack-page state id)] (let [page (stpr/pack-page state id)]
(->> (rp/do :update/page page) (->> (rp/do :update/page page)
(rx/mapcat on-success) (rx/map on-success)
(rx/catch on-failure)))))) (rx/catch on-failure))))))
(defn sync-page (defn sync-page
@ -120,9 +129,13 @@
(let [page (get-in state [:pages-by-id id])] (let [page (get-in state [:pages-by-id id])]
(if (:history page) (if (:history page)
(rx/empty) (rx/empty)
(rx/of (sync-page id)
(fetch-page-history id) (rx/merge
(fetch-pinned-page-history id)))))) (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 (defn update-page
[id] [id]