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

Improved history refresh mechanism.

This commit is contained in:
Andrey Antukh 2016-03-31 21:47:25 +03:00
parent b96a554c44
commit 41aa1eb8f5
4 changed files with 33 additions and 13 deletions

View file

@ -89,14 +89,37 @@
(defrecord CleanPageHistory []
rs/UpdateEvent
(-apply-update [_ state]
(-> state
(assoc-in [:workspace :history :items] nil)
(assoc-in [:workspace :history :selected] nil))))
(println "CleanPageHistory")
(assoc-in state [:workspace :history] {})))
(defn clean-page-history
[]
(CleanPageHistory.))
(defn clean-page-history?
[v]
(instance? CleanPageHistory v))
;; --- Watch Page Changes
(defrecord WatchPageChanges []
rs/WatchEvent
(-apply-watch [_ state s]
(println "WatchPageChanges")
(let [stoper (->> (rx/filter clean-page-history? s)
(rx/take 1))]
(->> (rx/filter udp/page-synced? s)
(rx/take-until stoper)
(rx/map (comp :id :page))
(rx/pr-log "watcher:")
(rx/mapcat #(rx/of
(fetch-page-history %)
(fetch-pinned-page-history %)))))))
(defn watch-page-changes
[]
(WatchPageChanges.))
;; --- Select Page History
(defrecord SelectPageHistory [item]

View file

@ -119,9 +119,6 @@
;; --- Update Page
(declare fetch-page-history)
(declare fetch-pinned-page-history)
(defrecord UpdatePage [id]
rs/WatchEvent
(-apply-watch [this state s]
@ -129,12 +126,11 @@
(let [page (get-in state [:pages-by-id id])]
(if (:history page)
(rx/empty)
(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)))))))))
(rx/of (sync-page id))))))
(defn update-page?
[v]
(instance? UpdatePage v))
(defn update-page
[id]

View file

@ -55,7 +55,6 @@
[own]
(let [profile (rum/react profile-l)
local (:rum/local own)]
(println "user-render" profile)
(html
[:div.user-zone {:on-mouse-enter #(swap! local assoc :open true)
:on-mouse-leave #(swap! local assoc :open false)}

View file

@ -35,6 +35,7 @@
(let [[projectid pageid] (:rum/props own)]
(rs/emit! (dw/initialize projectid pageid)
(udp/fetch-pages projectid)
(udh/watch-page-changes)
(udh/fetch-page-history pageid)
(udh/fetch-pinned-page-history pageid))
own))
@ -78,6 +79,7 @@
(defn- workspace-will-unmount
[own]
(rs/emit! (udh/clean-page-history))
(let [sub1 (::sub1 own)
sub2 (::sub2 own)]
(.close sub1)