diff --git a/src/day8/re_frame/trace/metamorphic.cljc b/src/day8/re_frame/trace/metamorphic.cljc index f295207..0513d32 100644 --- a/src/day8/re_frame/trace/metamorphic.cljc +++ b/src/day8/re_frame/trace/metamorphic.cljc @@ -125,6 +125,21 @@ (= (:operation event) [:idle :add-event]))) +(defn subscription? [trace] + (= "sub" (namespace (:op-type trace)))) + +(defn subscription-created? [trace] + (= :sub/create (:op-type trace))) + +(defn subscription-re-run? [trace] + (= :sub/run (:op-type trace))) + +(defn subscription-destroyed? [trace] + (= :sub/dispose (:op-type trace))) + +(defn subscription-not-run? [trace] + false) + (defn finish-run? [event] (and (fsm-trigger? event) (= (:operation event) diff --git a/src/day8/re_frame/trace/subs.cljs b/src/day8/re_frame/trace/subs.cljs index 622b010..679b1c7 100644 --- a/src/day8/re_frame/trace/subs.cljs +++ b/src/day8/re_frame/trace/subs.cljs @@ -257,3 +257,86 @@ :<- [:traces/current-event-traces] (fn [traces] (not (empty? traces)))) + +;; + +(rf/reg-sub + :subs/all-sub-traces + :<- [:traces/current-event-traces] + (fn [traces] + (filter metam/subscription? traces))) + +(defn sub-sort-val + [sub] + (case (:type sub) + :created 1 + :re-run 2 + :destroyed 3 + :not-run 4)) + +(def subscription-comparator + (fn [x y] + (compare (sub-sort-val x) (sub-sort-val y)))) + +(defn sub-op-type->type [t] + (case (:op-type t) + :sub/create :created + :sub/run :re-run + :sub/dispose :destroyed + + :not-run)) + +(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) + :type pod-type + :layer "2" + :path path-str + + ;; TODO: data for sub + ;; TODO: get layer level + ;; TODO: Get not run subscriptions + + :open? false + :diff false})) + traces) + + run-multiple? (frequencies (map :path 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/created-count + :<- [:subs/all-sub-traces] + (fn [traces] + (count (filter metam/subscription-created? traces)))) + +(rf/reg-sub + :subs/re-run-count + :<- [:subs/all-sub-traces] + (fn [traces] + (count (filter metam/subscription-re-run? traces)))) + +(rf/reg-sub + :subs/destroyed-count + :<- [:subs/all-sub-traces] + (fn [traces] + (count (filter metam/subscription-destroyed? traces)))) + +(rf/reg-sub + :subs/not-run-count + :<- [:subs/all-sub-traces] + (fn [traces] + (count (filter metam/subscription-not-run? traces)))) diff --git a/src/day8/re_frame/trace/view/subs.cljs b/src/day8/re_frame/trace/view/subs.cljs index 7d4d4a8..4e431ec 100644 --- a/src/day8/re_frame/trace/view/subs.cljs +++ b/src/day8/re_frame/trace/view/subs.cljs @@ -45,12 +45,16 @@ :not-run "#bdbdbd"}] (get types type "black"))) -(defn tag-desc [type] - (let [types {:created {:long "CREATED" :short "CREATED"} - :destroyed {:long "DESTROYED" :short "DESTROY"} - :re-run {:long "RE-RUN" :short "RE-RUN" } - :not-run {:long "NOT-RUN" :short "NOT-RUN"}}] - (get types type "???"))) +(def tag-types {:created {:long "CREATED" :short "CREATED"} + :destroyed {:long "DESTROYED" :short "DESTROY"} + :re-run {:long "RE-RUN" :short "RE-RUN"} + :not-run {:long "NOT-RUN" :short "NOT-RUN"}}) + +(defn long-tag-desc [type] + (get-in tag-types [type :long] "???")) + +(defn short-tag-desc [type] + (get-in tag-types [type :short] "???")) (defn tag [type label] [rc/box @@ -73,39 +77,43 @@ [tag type label]]]) (defn panel-header [] - [rc/h-box - :justify :between - :align :center - :margin (css-join common/gs-19s "0px") - :children [[rc/h-box - :align :center - :gap common/gs-19s - :height "48px" - :padding (css-join "0px" common/gs-19s) - :style {:background-color "#fafbfc" - :border "1px solid #e3e9ed" - :border-radius "3px"} - :children [[:span {:style {:color "#828282" - :font-size "18px" - :font-weight "lighter"}} - "Summary:"] - [title-tag :created (-> :created tag-desc :long) 2] - [title-tag :re-run (-> :re-run tag-desc :long) 44] - [title-tag :destroyed (-> :destroyed tag-desc :long) 1] - [title-tag :not-run (-> :not-run tag-desc :long) 12]]] - [rc/h-box - :align :center - :gap common/gs-19s - :height "48px" - :padding (css-join "0px" common/gs-19s) - :style {:background-color "#fafbfc" - :border "1px solid #e3e9ed" - :border-radius "3px"} - :children [[rc/checkbox - :model true - :label [:span "Ignore unchanged" [:br] "layer 2 subs"] - :style {:margin-top "6px"} - :on-change #()]]]]]) + (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])] + [rc/h-box + :justify :between + :align :center + :margin (css-join common/gs-19s "0px") + :children [[rc/h-box + :align :center + :gap common/gs-19s + :height "48px" + :padding (css-join "0px" common/gs-19s) + :style {:background-color "#fafbfc" + :border "1px solid #e3e9ed" + :border-radius "3px"} + :children [[:span {:style {:color "#828282" + :font-size "18px" + :font-weight "lighter"}} + "Summary:"] + [title-tag :created (long-tag-desc :created) @created-count] + [title-tag :re-run (long-tag-desc :re-run) @re-run-count] + [title-tag :destroyed (long-tag-desc :destroyed) @destroyed-count] + [title-tag :not-run (long-tag-desc :not-run) @not-run-count]]] + [rc/h-box + :align :center + :gap common/gs-19s + :height "48px" + :padding (css-join "0px" common/gs-19s) + :style {:background-color "#fafbfc" + :border "1px solid #e3e9ed" + :border-radius "3px"} + :children [[rc/checkbox + :model true + :label [:span "Ignore unchanged" [:br] "layer 2 subs"] + :style {:margin-top "6px"} + :on-change #()]]]]])) (defn pod-header [{:keys [id type layer path open? diff?]}] [rc/h-box @@ -129,7 +137,7 @@ :child [:span.arrow (if open? "▼" "▶")]]] [rc/box :width "64px" ;; (100-36)px from box above - :child [tag type (-> type tag-desc :short)]] + :child [tag type (short-tag-desc type)]] [rc/h-box :size "auto" :class "app-db-path--path-header" @@ -222,13 +230,14 @@ :children [[rc/label :label "There are no subscriptions to show"]]]) (defn pod-section [] - [rc/v-box - :gap pod-gap - :children (if (empty? @*pods) - [[no-pods]] - (doall (for [p @*pods] - ^{:key (str p)} - [pod p])))]) + (let [all-subs @(rf/subscribe [:subs/all-subs])] + [rc/v-box + :gap pod-gap + :children (if (empty? all-subs) + [[no-pods]] + (doall (for [p all-subs] + ^{:key (:id p)} + [pod p])))])) (defn render [] []