Add setting to ignore unchanged layer 2 subscriptions

This commit is contained in:
Daniel Compton 2018-01-17 13:43:43 +13:00
parent b07514d001
commit 18d0a9b145
5 changed files with 82 additions and 20 deletions

View File

@ -24,4 +24,5 @@
(rf/dispatch [:traces/update-show-epoch-traces? true]) ;; TODO: source this from LS.
(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])))
(rf/dispatch [:global/add-unload-hook])
(rf/dispatch [:app-db/reagent-id])))

View File

@ -6,6 +6,7 @@
[clojure.string :as str]
[goog.object]
[re-frame.db]
[re-frame.interop]
[day8.re-frame.trace.view.container :as container]
[day8.re-frame.trace.styles :as styles]
[clojure.set :as set]
@ -399,6 +400,12 @@
(localstorage/save! "app-db-json-ml-expansions" new-paths)
new-paths)))
(rf/reg-event-db
:app-db/reagent-id
[(rf/path [:app-db :reagent-id])]
(fn [paths _]
(re-frame.interop/reagent-id re-frame.db/app-db)))
(rf/reg-event-db
:snapshot/load-snapshot
(fn [db [_ new-db]]
@ -432,3 +439,11 @@
[(rf/path [:traces :all-traces])]
(fn [_ [_ traces]]
traces))
;;
(rf/reg-event-db
:subs/ignore-unchanged-subs?
[(rf/path [:subs :ignore-unchanged-subs?])]
(fn [_ [_ ignore?]]
ignore?))

View File

@ -126,10 +126,12 @@
[:idle :add-event])))
(defn subscription? [trace]
(= "sub" (namespace (:op-type trace))))
(and (= "sub" (namespace (:op-type trace)))
(not (get-in trace [:tags :cached?]))))
(defn subscription-created? [trace]
(= :sub/create (:op-type trace)))
(and (= :sub/create (:op-type trace))
(not (get-in trace [:tags :cached?]))))
(defn subscription-re-run? [trace]
(= :sub/run (:op-type trace)))
@ -140,6 +142,13 @@
(defn subscription-not-run? [trace]
false)
(defn unchanged-l2-subscription? [sub]
;; TODO: check if value changed
(and
(= :re-run (:type sub))
(= 2 (:layer sub))))
(defn finish-run? [event]
(and (fsm-trigger? event)
(= (:operation event)

View File

@ -78,6 +78,12 @@
(fn [expansions [_ path]]
(contains? expansions path)))
(rf/reg-sub
:app-db/reagent-id
:<- [:app-db/root]
(fn [root _]
(:reagent-id root)))
;;
(rf/reg-sub
@ -260,6 +266,11 @@
;;
(rf/reg-sub
:subs/root
(fn [db _]
(:subs db)))
(rf/reg-sub
:subs/all-sub-traces
:<- [:traces/current-event-traces]
@ -289,19 +300,19 @@
(rf/reg-sub
:subs/all-subs
:<- [:subs/all-sub-traces]
(fn [traces]
(let [raw [{:id (gensym) :type :destroyed :layer "3" :path "[:todo/blah]" :open? false :diff? false}
{:id (gensym) :type :re-run :layer "2" :path "[:todo/blah]" :open? false :diff? false}
{:id (gensym) :type :created :layer "3" :path "[:todo/completed]" :open? false :diff? true}
{:id (gensym) :type :re-run :layer "3" :path "[:todo/completed]" :open? false :diff? false}
{:id (gensym) :type :not-run :layer "3" :path "[:todo/blah]" :open? false :diff? false}]
raw (map (fn [trace] (let [pod-type (sub-op-type->type trace)
path-str (pr-str (get-in trace [:tags :query-v]))]
{:id (str pod-type path-str)
:<- [:app-db/reagent-id]
(fn [[traces app-db-id]]
(js/console.log "appdb id" app-db-id)
(let [raw (map (fn [trace] (let [pod-type (sub-op-type->type trace)
path-str (pr-str (get-in trace [:tags :query-v]))
layer (if (some #(= app-db-id %) (get-in trace [:tags :input-signals]))
2
3)]
{:id (str pod-type (get-in trace [:tags :reaction]))
:type pod-type
:layer "2"
:layer layer
:path path-str
:value (get-in trace [:tags :value])
;; TODO: data for sub
;; TODO: get layer level
@ -311,12 +322,24 @@
:diff false}))
traces)
run-multiple? (frequencies (map :path raw))]
;; Filter out run if it was created
;; Group together run time
run-multiple? (frequencies (map :id raw))]
(js/console.log "Run Multiple" run-multiple?)
(js/console.log "Traces" traces)
(js/console.log "Raw" raw)
(sort-by identity subscription-comparator raw))))
(rf/reg-sub
:subs/visible-subs
:<- [:subs/all-subs]
:<- [:subs/ignore-unchanged-subs?]
(fn [[all-subs ignore-unchanged-l2?]]
(if ignore-unchanged-l2?
(remove metam/unchanged-l2-subscription? all-subs)
all-subs)))
(rf/reg-sub
:subs/created-count
:<- [:subs/all-sub-traces]
@ -340,3 +363,15 @@
:<- [:subs/all-sub-traces]
(fn [traces]
(count (filter metam/subscription-not-run? traces))))
(rf/reg-sub
:subs/unchanged-l2-subs-count
:<- [:subs/all-subs]
(fn [subs]
(count (filter metam/unchanged-l2-subscription? subs))))
(rf/reg-sub
:subs/ignore-unchanged-subs?
:<- [:subs/root]
(fn [subs _]
(:ignore-unchanged-subs? subs true)))

View File

@ -81,7 +81,9 @@
(let [created-count (rf/subscribe [:subs/created-count])
re-run-count (rf/subscribe [:subs/re-run-count])
destroyed-count (rf/subscribe [:subs/destroyed-count])
not-run-count (rf/subscribe [:subs/not-run-count])]
not-run-count (rf/subscribe [:subs/not-run-count])
ignore-unchanged? (rf/subscribe [:subs/ignore-unchanged-subs?])
ignore-unchanged-l2-count (rf/subscribe [:subs/unchanged-l2-subs-count])]
[rc/h-box
:justify :between
:align :center
@ -111,10 +113,10 @@
:border "1px solid #e3e9ed"
:border-radius "3px"}
:children [[rc/checkbox
:model true
:label [:span "Ignore unchanged" [:br] "layer 2 subs"]
:model ignore-unchanged?
:label [:span "Ignore " [:b {:style {:font-weight "700"}} @ignore-unchanged-l2-count] " unchanged" [:br] "layer 2 subs"]
:style {:margin-top "6px"}
:on-change #()]]]]]))
:on-change #(rf/dispatch [:subs/ignore-unchanged-subs? %])]]]]]))
(defn pod-header [{:keys [id type layer path open? diff?]}]
[rc/h-box
@ -231,7 +233,7 @@
:children [[rc/label :label "There are no subscriptions to show"]]])
(defn pod-section []
(let [all-subs @(rf/subscribe [:subs/all-subs])]
(let [all-subs @(rf/subscribe [:subs/visible-subs])]
[rc/v-box
:gap pod-gap
:children (if (empty? all-subs)