diff --git a/frontend/uxbox/core.cljs b/frontend/uxbox/core.cljs index d8a82c8df1..6dca13cc6f 100644 --- a/frontend/uxbox/core.cljs +++ b/frontend/uxbox/core.cljs @@ -1,6 +1,7 @@ (ns uxbox.core (:require [beicon.core :as rx] - [uxbox.state :as s] + [cats.labs.lens :as l] + [uxbox.state :as st] [uxbox.router :as rt] [uxbox.rstore :as rs] [uxbox.ui :as ui] @@ -8,12 +9,24 @@ (enable-console-print!) +(defn main + "Initialize the storage subsystem." + [] + (let [lens (l/select-keys [:pages-by-id + :projects-by-id]) + stream (->> (l/focus-atom lens st/state) + (rx/from-atom) + (rx/debounce 1000) + (rx/tap #(println "[save]")))] + (rx/on-value stream #(dl/persist-state %)))) + (defonce +setup+ (do (println "bootstrap") + (st/init) (rt/init) (ui/init) (rs/emit! (dl/load-data)) - (rx/on-value s/stream #(dl/persist-state %)))) + (main))) diff --git a/frontend/uxbox/state.cljs b/frontend/uxbox/state.cljs index e743945dc8..b59637d2e1 100644 --- a/frontend/uxbox/state.cljs +++ b/frontend/uxbox/state.cljs @@ -2,8 +2,6 @@ (:require [beicon.core :as rx] [uxbox.rstore :as rs])) -(enable-console-print!) - (defonce state (atom {})) (defonce stream @@ -17,4 +15,8 @@ :projects-by-id {} :pages-by-id {}})) -(rx/to-atom stream state) + +(defn init + "Initialize the state materialization." + [] + (rx/to-atom stream state)) diff --git a/profiles.clj b/profiles.clj index 0a29e719f5..365d4c8e2a 100644 --- a/profiles.clj +++ b/profiles.clj @@ -43,7 +43,7 @@ [rum "0.6.0"] [bouncer "0.3.3"] [funcool/promesa "0.6.0"] - [funcool/beicon "0.3.0"] + [funcool/beicon "0.4.0"] [cljsjs/moment "2.10.6-0"] [figwheel-sidecar "0.5.0-2" :scope "test"] [bidi "1.21.0"]