Save and load JSONML expansions to localstorage

This commit is contained in:
Daniel Compton 2017-11-16 15:36:59 +13:00
parent 87e5679ebb
commit a6bf2be052
3 changed files with 13 additions and 8 deletions

View File

@ -7,13 +7,14 @@
show-panel? (localstorage/get "show-panel" false) show-panel? (localstorage/get "show-panel" false)
selected-tab (localstorage/get "selected-tab" :traces) selected-tab (localstorage/get "selected-tab" :traces)
filter-items (localstorage/get "filter-items" []) filter-items (localstorage/get "filter-items" [])
app-db-paths (localstorage/get "app-db-paths" '())] app-db-paths (localstorage/get "app-db-paths" '())
json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{})]
(rf/dispatch [:settings/panel-width% panel-width%]) (rf/dispatch [:settings/panel-width% panel-width%])
(rf/dispatch [:settings/show-panel? show-panel?]) (rf/dispatch [:settings/show-panel? show-panel?])
(rf/dispatch [:settings/selected-tab selected-tab]) (rf/dispatch [:settings/selected-tab selected-tab])
(rf/dispatch [:traces/filter-items filter-items]) (rf/dispatch [:traces/filter-items filter-items])
(rf/dispatch [:app-db/paths app-db-paths]) (rf/dispatch [:app-db/paths app-db-paths])
(rf/dispatch [:app-db/set-json-ml-paths #{}]) (rf/dispatch [:app-db/set-json-ml-paths json-ml-paths])
(rf/dispatch [:global/add-unload-hook]) (rf/dispatch [:global/add-unload-hook])
(when show-panel? (when show-panel?
(rf/dispatch [:global/enable-tracing])))) (rf/dispatch [:global/enable-tracing]))))

View File

@ -186,13 +186,17 @@
(rf/reg-event-db (rf/reg-event-db
:app-db/set-json-ml-paths :app-db/set-json-ml-paths
[(rf/path [:app-db :json-ml-expansions])]
(fn [db [_ paths]] (fn [db [_ paths]]
(assoc-in db [:app-db :json-ml-paths] paths))) (localstorage/save! "app-db-json-ml-expansions" paths)
paths))
(rf/reg-event-db (rf/reg-event-db
:app-db/toggle-expansion :app-db/toggle-expansion
[(rf/path [:app-db :json-ml-paths])] [(rf/path [:app-db :json-ml-expansions])]
(fn [paths [_ path]] (fn [paths [_ path]]
(if (contains? paths path) (let [new-paths (if (contains? paths path)
(disj paths path) (disj paths path)
(conj paths path)))) (conj paths path))]
(localstorage/save! "app-db-json-ml-expansions" new-paths)
new-paths)))

View File

@ -47,7 +47,7 @@
:app-db/expansions :app-db/expansions
:<- [:app-db/root] :<- [:app-db/root]
(fn [app-db-settings _] (fn [app-db-settings _]
(get app-db-settings :json-ml-paths))) (get app-db-settings :json-ml-expansions)))
(rf/reg-sub (rf/reg-sub
:app-db/node-expanded? :app-db/node-expanded?