Refactor match handling to return a map with multiple keys
This allows us to parse and collect other information when receiving events, rather than calculating them at runtime when some information may not be available (like dropped traces).
This commit is contained in:
parent
0994626814
commit
889bfc6a3a
|
@ -503,18 +503,12 @@
|
|||
all-traces (reduce conj previous-traces filtered-traces)
|
||||
parse-state (metam/parse-traces parse-state filtered-traces)
|
||||
new-matches (:partitions parse-state)
|
||||
previous-matches (get-in db [:epochs :matches-and-subs] [])
|
||||
previous-matches (get-in db [:epochs :matches] [])
|
||||
parse-state (assoc parse-state :partitions []) ;; Remove matches we know about
|
||||
new-matches (remove (fn [match]
|
||||
(let [event (get-in (metam/matched-event match) [:tags :event])]
|
||||
(contains? events-to-ignore (first event)))) new-matches)
|
||||
sub-state {}
|
||||
|
||||
;; Retrieve previous state
|
||||
;; Save new states, removing unretained ones (maybe by mapping with match?)
|
||||
;; Save final state
|
||||
|
||||
|
||||
subscription-match-state (rest
|
||||
(reductions (fn [state match]
|
||||
(let [epoch-traces (into []
|
||||
|
@ -540,10 +534,10 @@
|
|||
sub-state)
|
||||
(assoc :run? true
|
||||
:value (:value tags))
|
||||
(update :order conj :sub/run))))
|
||||
(update :order (fnil conj []) :sub/run))))
|
||||
:sub/dispose (-> (assoc-in state [reaction-id :disposed?] true)
|
||||
(update-in [reaction-id :order] conj :sub/dispose))
|
||||
(do (js/console.warn "Unhandled sub trace" trace)
|
||||
(update-in [reaction-id :order] (fnil conj []) :sub/dispose))
|
||||
(do (js/console.warn "Unhandled sub trace, this is a bug, report to re-frame-trace please" trace)
|
||||
state))))
|
||||
reset-state))))
|
||||
sub-state
|
||||
|
@ -556,7 +550,6 @@
|
|||
start-of-epoch (nth epoch-traces 0)
|
||||
finish-run (or (first (filter metam/finish-run? epoch-traces))
|
||||
(utils/last-in-vec epoch-traces))]
|
||||
;; Note, sometimes we still end up with a nil elapsed time here, look into more
|
||||
{:re-frame/event-time (metam/elapsed-time start-of-epoch finish-run)}))
|
||||
new-matches)
|
||||
|
||||
|
@ -592,13 +585,11 @@
|
|||
(assoc-in [:traces :all-traces] retained-traces)
|
||||
(update :epochs (fn [epochs]
|
||||
(assoc epochs
|
||||
:matches (into [] (map :match-info) retained-matches)
|
||||
:matches-by-id (into {} (map (juxt first-match-id :match-info)) retained-matches)
|
||||
:matches retained-matches
|
||||
:matches-by-id (into {} (map (juxt first-match-id identity)) retained-matches)
|
||||
:match-ids (mapv first-match-id retained-matches)
|
||||
:parse-state parse-state
|
||||
:subscription-info subscription-info
|
||||
:matches-and-subs retained-matches
|
||||
:matches-by-id2 (into {} (map (juxt first-match-id identity)) retained-matches))))))
|
||||
:subscription-info subscription-info)))))
|
||||
;; Else
|
||||
db)))
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@
|
|||
(:epochs db)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/current-match
|
||||
:epochs/current-match-state
|
||||
:<- [:epochs/epoch-root]
|
||||
:<- [:epochs/match-ids]
|
||||
(fn [[epochs match-ids] _]
|
||||
|
@ -225,19 +225,10 @@
|
|||
match)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/current-match-state
|
||||
:<- [:epochs/epoch-root]
|
||||
:<- [:epochs/match-ids]
|
||||
(fn [[epochs match-ids] _]
|
||||
(let [current-id (:current-epoch-id epochs)
|
||||
match (cond
|
||||
(nil? current-id) (last (:matches-and-subs epochs))
|
||||
(< current-id (first match-ids)) (first (:matches-and-subs epochs))
|
||||
;; This case seems impossible, but can happen if the user filters out
|
||||
;; an event that they are 'on'.
|
||||
(> current-id (last match-ids)) (last (:matches-and-subs epochs))
|
||||
:else (get (:matches-by-id2 epochs) current-id))]
|
||||
match)))
|
||||
:epochs/current-match
|
||||
:<- [:epochs/current-match-state]
|
||||
(fn [match-state _]
|
||||
(:match-info match-state)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/current-event-trace
|
||||
|
@ -341,17 +332,8 @@
|
|||
:timing/event-processing-time
|
||||
:<- [:epochs/current-match-state]
|
||||
(fn [match]
|
||||
(utils/spy "match" match)
|
||||
(get-in match [:timing :re-frame/event-time])))
|
||||
|
||||
#_(rf/reg-sub
|
||||
:timing/event-processing-time
|
||||
:<- [:traces/current-event-traces]
|
||||
(fn [traces]
|
||||
(let [start-of-epoch (nth traces 0)
|
||||
finish-run (first (filter metam/finish-run? traces))]
|
||||
(metam/elapsed-time start-of-epoch finish-run))))
|
||||
|
||||
(rf/reg-sub
|
||||
:timing/render-time
|
||||
:<- [:traces/current-event-traces]
|
||||
|
|
|
@ -16,14 +16,15 @@
|
|||
|
||||
[rc/label :label "Epochs"]
|
||||
(let [current-match @(rf/subscribe [:epochs/current-match])]
|
||||
(for [match (:matches @(rf/subscribe [:epochs/epoch-root]))]
|
||||
^{:key (:id (first match))}
|
||||
(for [match (:matches @(rf/subscribe [:epochs/epoch-root]))
|
||||
:let [match-info (:match-info match)]]
|
||||
^{:key (:id (first match-info))}
|
||||
[rc/v-box
|
||||
:style {:border "1px solid black"
|
||||
:font-weight (if (= current-match match)
|
||||
:font-weight (if (= current-match match-info)
|
||||
"bold"
|
||||
"normal")}
|
||||
:children (doall (map (fn [event] [rc/label :label (prn-str event)]) (metam/summarise-match match)))
|
||||
:children (doall (map (fn [event] [rc/label :label (prn-str event)]) (metam/summarise-match match-info)))
|
||||
]))
|
||||
]]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue