Save showing epoch traces setting to localstorage

This commit is contained in:
Daniel Compton 2018-02-09 01:37:59 +13:00
parent 4853a9b249
commit 578fdb089c
4 changed files with 34 additions and 12 deletions

View File

@ -10,6 +10,7 @@
app-db-paths (into (sorted-map) (localstorage/get "app-db-paths" {}))
json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{})
external-window? (localstorage/get "external-window?" false)
show-epoch-traces? (localstorage/get "show-epoch-traces?" true)
using-trace? (localstorage/get "using-trace?" true)
ignored-events (localstorage/get "ignored-events" {})
low-level-trace (localstorage/get "low-level-trace" {:reagent true :re-frame true})
@ -33,7 +34,7 @@
(rf/dispatch [:global/launch-external]))
(rf/dispatch [:traces/filter-items filter-items])
(rf/dispatch [:traces/set-categories categories])
(rf/dispatch [:traces/update-show-epoch-traces? true]) ;; TODO: source this from LS.
(rf/dispatch [:trace-panel/update-show-epoch-traces? show-epoch-traces?])
(rf/dispatch [:app-db/paths app-db-paths])
(rf/dispatch [:app-db/set-json-ml-paths json-ml-paths])
(rf/dispatch [:global/add-unload-hook])

View File

@ -14,6 +14,20 @@
[day8.re-frame.trace.metamorphic :as metam]
[re-frame.trace]))
(defn fixed-after
;; Waiting on https://github.com/Day8/re-frame/issues/447
[f]
(rf/->interceptor
:id :after
:after (fn after-after
[context]
(let [db (if (contains? (:effects context) :db)
(get-in context [:effects :db])
(get-in context [:coeffects :db]))
event (get-in context [:coeffects :event])]
(f db event) ;; call f for side effects
context)))) ;; context is unchanged
(defn log-trace? [trace]
(let [render-operation? (or (= (:op-type trace) :render)
(= (:op-type trace) :componentWillUnmount))
@ -122,7 +136,7 @@
(assoc-in db [:settings :number-of-epochs] num))))
(def ignored-event-mw
[(rf/path [:settings :ignored-events]) (rf/after #(localstorage/save! "ignored-events" %))])
[(rf/path [:settings :ignored-events]) (fixed-after #(localstorage/save! "ignored-events" %))])
(rf/reg-event-db
:settings/add-ignored-event
@ -154,7 +168,7 @@
ignored-events))
(def filtered-view-trace-mw
[(rf/path [:settings :filtered-view-trace]) (rf/after #(localstorage/save! "filtered-view-trace" %))])
[(rf/path [:settings :filtered-view-trace]) (fixed-after #(localstorage/save! "filtered-view-trace" %))])
(rf/reg-event-db
:settings/add-filtered-view-trace
@ -185,7 +199,7 @@
(fn [_ [_ ignored-events]]
ignored-events))
(def low-level-trace-mw [(rf/path [:settings :low-level-trace]) (rf/after #(localstorage/save! "low-level-trace" %))])
(def low-level-trace-mw [(rf/path [:settings :low-level-trace]) (fixed-after #(localstorage/save! "low-level-trace" %))])
(rf/reg-event-db
:settings/set-low-level-trace
@ -347,16 +361,18 @@
(fn [categories [_ new-categories]]
new-categories))
(rf/reg-event-db
:traces/update-show-epoch-traces?
[(rf/path [:traces :show-epoch-traces?])]
(fn [_ [_ show-epoch-traces?]]
:trace-panel/update-show-epoch-traces?
[(rf/path [:trace-panel :show-epoch-traces?]) (fixed-after #(localstorage/save! "show-epoch-traces?" %))]
(fn [_ [k show-epoch-traces?]]
(js/console.log k show-epoch-traces?)
show-epoch-traces?))
;; App DB
(def app-db-path-mw
[(rf/path [:app-db :paths]) (rf/after #(localstorage/save! "app-db-paths" %))])
[(rf/path [:app-db :paths]) (fixed-after #(localstorage/save! "app-db-paths" %))])
(rf/reg-event-db
:app-db/create-path

View File

@ -124,6 +124,11 @@
(fn [db _]
(:traces db)))
(rf/reg-sub
:trace-panel/root
(fn [db _]
(:trace-panel db)))
(rf/reg-sub
:traces/filter-items
(fn [db _]
@ -183,8 +188,8 @@
filter-ignored-views)
(rf/reg-sub
:traces/show-epoch-traces?
:<- [:traces/trace-root]
:trace-panel/show-epoch-traces?
:<- [:trace-panel/root]
(fn [trace-root]
(:show-epoch-traces? trace-root)))

View File

@ -87,7 +87,7 @@
end (rf/subscribe [:epochs/ending-trace-id])
traces (rf/subscribe [:traces/all-visible-traces])
current-traces (rf/subscribe [:traces/current-event-visible-traces])
show-epoch-traces? (rf/subscribe [:traces/show-epoch-traces?])]
show-epoch-traces? (rf/subscribe [:trace-panel/show-epoch-traces?])]
(fn []
(let [toggle-category-fn #(rf/dispatch [:traces/toggle-categories %])
traces-to-filter (if @show-epoch-traces?
@ -127,7 +127,7 @@
"internals"]]
[rc/checkbox
:model show-epoch-traces?
:on-change #(rf/dispatch [:traces/update-show-epoch-traces? %])
:on-change #(rf/dispatch [:trace-panel/update-show-epoch-traces? %])
:label "Show only traces for this epoch?"]
[:div.filter-fields
[:select {:value @filter-type