From 41aa1eb8f58f1e600b54f9b99520c28e083c758a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 31 Mar 2016 21:47:25 +0300 Subject: [PATCH] Improved history refresh mechanism. --- src/uxbox/data/history.cljs | 29 ++++++++++++++++++++++++++--- src/uxbox/data/pages.cljs | 14 +++++--------- src/uxbox/ui/users.cljs | 1 - src/uxbox/ui/workspace.cljs | 2 ++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/uxbox/data/history.cljs b/src/uxbox/data/history.cljs index 7914b5383..c03678500 100644 --- a/src/uxbox/data/history.cljs +++ b/src/uxbox/data/history.cljs @@ -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] diff --git a/src/uxbox/data/pages.cljs b/src/uxbox/data/pages.cljs index ffff2a83c..17fd0996c 100644 --- a/src/uxbox/data/pages.cljs +++ b/src/uxbox/data/pages.cljs @@ -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] diff --git a/src/uxbox/ui/users.cljs b/src/uxbox/ui/users.cljs index 2b6c6c152..2f7467689 100644 --- a/src/uxbox/ui/users.cljs +++ b/src/uxbox/ui/users.cljs @@ -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)} diff --git a/src/uxbox/ui/workspace.cljs b/src/uxbox/ui/workspace.cljs index 685693d7d..1addc4c2f 100644 --- a/src/uxbox/ui/workspace.cljs +++ b/src/uxbox/ui/workspace.cljs @@ -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)