diff --git a/src/uxbox/main/data/history.cljs b/src/uxbox/main/data/history.cljs index 4350f7ba62..e2a81e28a5 100644 --- a/src/uxbox/main/data/history.cljs +++ b/src/uxbox/main/data/history.cljs @@ -89,39 +89,22 @@ ([id params] (map->FetchPageHistory (assoc params :id id)))) -;; --- Clean Page History - -(defrecord CleanPageHistory [] - rs/UpdateEvent - (-apply-update [_ state] - (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] - (let [stoper (->> (rx/filter clean-page-history? s) - (rx/take 1))] - (->> (rx/filter udp/page-synced? s) - (rx/take-until stoper) - (rx/delay 1000) - (rx/map (comp :id :page)) - (rx/mapcat #(rx/of - (fetch-page-history %) - (fetch-pinned-page-history %))))))) - (defn watch-page-changes + "A function that starts watching for `IPageUpdate` + events emited to the global event stream and just + reacts on them emiting an other event that just + persists the state of the page in an undo stack." [] - (WatchPageChanges.)) + (letfn [(on-value [id] + (rs/emit! (fetch-page-history id) + (fetch-pinned-page-history id)))] + (as-> rs/stream $ + (rx/filter udp/page-synced? $) + (rx/delay 500 $) + (rx/map (comp :id :page) $) + (rx/on-value $ on-value)))) ;; --- Select Page History diff --git a/src/uxbox/main/ui/workspace.cljs b/src/uxbox/main/ui/workspace.cljs index 2422c20d01..f84b2447cd 100644 --- a/src/uxbox/main/ui/workspace.cljs +++ b/src/uxbox/main/ui/workspace.cljs @@ -38,8 +38,7 @@ (defn- workspace-will-mount [own] (let [[projectid pageid] (:rum/args own)] - (rs/emit! (dw/initialize projectid pageid) - (udh/watch-page-changes)) + (rs/emit! (dw/initialize projectid pageid)) own)) (defn- workspace-did-mount @@ -47,23 +46,25 @@ (let [[projectid pageid] (:rum/args own) sub1 (scroll/watch-scroll-interactions own) sub2 (udp/watch-page-changes pageid) + sub3 (udh/watch-page-changes) dom (mx/ref-node own "workspace-canvas")] ;; Set initial scroll position (set! (.-scrollLeft dom) (* c/canvas-start-scroll-x @wb/zoom-ref)) (set! (.-scrollTop dom) (* c/canvas-start-scroll-y @wb/zoom-ref)) - (assoc own ::sub1 sub1 ::sub2 sub2))) + (assoc own + ::sub1 sub1 + ::sub2 sub2 + ::sub3 sub3))) (defn- workspace-will-unmount [own] - (rs/emit! (udh/clean-page-history)) - ;; Close subscriptions (.close (::sub1 own)) (.close (::sub2 own)) - - (dissoc own ::sub1 ::sub2)) + (.close (::sub3 own)) + (dissoc own ::sub1 ::sub2 ::sub3)) (defn- workspace-did-remount [old-state state]