Reformat all code

This commit is contained in:
Daniel Compton 2017-10-30 16:02:22 +13:00
parent 74faed83e3
commit 8ce90653dc
4 changed files with 197 additions and 197 deletions

View File

@ -133,7 +133,7 @@
(if (= :contains (:filter-type query))
(fn [trace]
(str/includes? (str/lower-case (str (:operation trace) " " (:op-type trace)))
(:query query)))
(:query query)))
(fn [trace]
(< (:query query) (:duration trace)))))
@ -157,140 +157,140 @@
(->>
visible-traces
(map-indexed (fn [index {:keys [op-type id operation tags duration] :as trace}]
(let [show-row? (get-in @trace-detail-expansions [:overrides id]
(let [show-row? (get-in @trace-detail-expansions [:overrides id]
(:show-all? @trace-detail-expansions))
op-name (if (vector? operation)
(second operation)
operation)
#_#__ (js/console.log (devtools/header-api-call tags))]
(list [:tr {:key id
:on-click (fn [ev]
(swap! trace-detail-expansions update-in [:overrides id]
#(if show-row? false (not %))))
:class (str/join " " ["trace--trace"
(case op-type
:sub/create "trace--sub-create"
:sub/run "trace--sub-run"
:event "trace--event"
:render "trace--render"
:re-frame.router/fsm-trigger "trace--fsm-trigger"
nil)])}
op-name (if (vector? operation)
(second operation)
operation)
#_#__ (js/console.log (devtools/header-api-call tags))]
(list [:tr {:key id
:on-click (fn [ev]
(swap! trace-detail-expansions update-in [:overrides id]
#(if show-row? false (not %))))
:class (str/join " " ["trace--trace"
(case op-type
:sub/create "trace--sub-create"
:sub/run "trace--sub-run"
:event "trace--event"
:render "trace--render"
:re-frame.router/fsm-trigger "trace--fsm-trigger"
nil)])}
[:td.trace--toggle
[:button.expansion-button (if show-row? "▼" "▶")]]
[:td.trace--op
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-type) :contains)
(.stopPropagation ev))}
(str op-type)]]
[:td.trace--op-string
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-name) :contains)
(.stopPropagation ev))}
(str op-name)]]
[:td.trace--meta
(.toFixed duration 1) " ms"]]
(when show-row?
[:tr.trace--details {:key (str id "-details")
:tab-index 0}
[:td]
[:td.trace--details-tags {:col-span 2
:on-click #(.log js/console tags)}
[:td.trace--toggle
[:button.expansion-button (if show-row? "▼" "▶")]]
[:td.trace--op
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-type) :contains)
(.stopPropagation ev))}
(str op-type)]]
[:td.trace--op-string
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-name) :contains)
(.stopPropagation ev))}
(str op-name)]]
[:td.trace--meta
(.toFixed duration 1) " ms"]]
(when show-row?
[:tr.trace--details {:key (str id "-details")
:tab-index 0}
[:td]
[:td.trace--details-tags {:col-span 2
:on-click #(.log js/console tags)}
[:div.trace--details-tags-text
(let [tag-str (with-out-str (pprint/pprint tags))
string-size-limit 400]
(if (< string-size-limit (count tag-str))
(str (subs tag-str 0 string-size-limit) " ...")
tag-str))]]
[:td.trace--meta.trace--details-icon
{:on-click #(.log js/console tags)}]]))))))))
(let [tag-str (with-out-str (pprint/pprint tags))
string-size-limit 400]
(if (< string-size-limit (count tag-str))
(str (subs tag-str 0 string-size-limit) " ...")
tag-str))]]
[:td.trace--meta.trace--details-icon
{:on-click #(.log js/console tags)}]]))))))))
(defn render-trace-panel []
(let [filter-input (r/atom "")
filter-items (r/atom (localstorage/get "filter-items" []))
filter-type (r/atom :contains)
input-error (r/atom false)
categories (r/atom #{:event :sub/run :sub/create})
trace-detail-expansions (r/atom {:show-all? false :overrides {}})]
(let [filter-input (r/atom "")
filter-items (r/atom (localstorage/get "filter-items" []))
filter-type (r/atom :contains)
input-error (r/atom false)
categories (r/atom #{:event :sub/run :sub/create})
trace-detail-expansions (r/atom {:show-all? false :overrides {}})]
(add-watch filter-items
:update-localstorage
(fn [_ _ _ new-state]
(localstorage/save! "filter-items" new-state)))
(fn []
(let [toggle-category-fn (fn [category-keys]
(swap! categories #(if (set/superset? % category-keys)
(set/difference % category-keys)
(set/union % category-keys))))
(let [toggle-category-fn (fn [category-keys]
(swap! categories #(if (set/superset? % category-keys)
(set/difference % category-keys)
(set/union % category-keys))))
visible-traces (cond->> @traces
(seq @categories) (filter (fn [trace] (when (contains? @categories (:op-type trace)) trace)))
(seq @filter-items) (filter (apply every-pred (map query->fn @filter-items))))
save-query (fn [_]
(if (and (= @filter-type :slower-than)
(js/isNaN (js/parseFloat @filter-input)))
(reset! input-error true)
(do
(reset! input-error false)
(add-filter filter-items @filter-input @filter-type))))]
visible-traces (cond->> @traces
(seq @categories) (filter (fn [trace] (when (contains? @categories (:op-type trace)) trace)))
(seq @filter-items) (filter (apply every-pred (map query->fn @filter-items))))
save-query (fn [_]
(if (and (= @filter-type :slower-than)
(js/isNaN (js/parseFloat @filter-input)))
(reset! input-error true)
(do
(reset! input-error false)
(add-filter filter-items @filter-input @filter-type))))]
[:div.tab-contents
[:div.filter
[:div.filter-control
[:ul.filter-categories "show: "
[:li.filter-category {:class (when (contains? @categories :event) "active")
:on-click #(toggle-category-fn #{:event})}
"events"]
[:li.filter-category {:class (when (contains? @categories :sub/run) "active")
:on-click #(toggle-category-fn #{:sub/run :sub/create})}
"subscriptions"]
[:li.filter-category {:class (when (contains? @categories :render) "active")
:on-click #(toggle-category-fn #{:render})}
"reagent"]
[:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active")
:on-click #(toggle-category-fn #{:re-frame.router/fsm-trigger :componentWillUnmount})}
"internals"]]
[:div.filter-fields
[:select {:value @filter-type
:on-change #(reset! filter-type (keyword (.. % -target -value)))}
[:option {:value "contains"} "contains"]
[:option {:value "slower-than"} "slower than"]]
[:div.filter-control-input {:style {:margin-left 10}}
[components/search-input {:on-save save-query
:on-change #(reset! filter-input (.. % -target -value))}]
(if @input-error
[:div.input-error {:style {:color "red" :margin-top 5}}
"Please enter a valid number."])]]]
[:ul.filter-items
(map (fn [item]
^{:key (:id item)}
[:li.filter-item
[:button.button
{:style {:margin 0}
:on-click (fn [event] (swap! filter-items #(remove (comp (partial = (:query item)) :query) %)))}
(:filter-type item) ": " [:span.filter-item-string (:query item)]]])
@filter-items)]]
[:div.filter
[:div.filter-control
[:ul.filter-categories "show: "
[:li.filter-category {:class (when (contains? @categories :event) "active")
:on-click #(toggle-category-fn #{:event})}
"events"]
[:li.filter-category {:class (when (contains? @categories :sub/run) "active")
:on-click #(toggle-category-fn #{:sub/run :sub/create})}
"subscriptions"]
[:li.filter-category {:class (when (contains? @categories :render) "active")
:on-click #(toggle-category-fn #{:render})}
"reagent"]
[:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active")
:on-click #(toggle-category-fn #{:re-frame.router/fsm-trigger :componentWillUnmount})}
"internals"]]
[:div.filter-fields
[:select {:value @filter-type
:on-change #(reset! filter-type (keyword (.. % -target -value)))}
[:option {:value "contains"} "contains"]
[:option {:value "slower-than"} "slower than"]]
[:div.filter-control-input {:style {:margin-left 10}}
[components/search-input {:on-save save-query
:on-change #(reset! filter-input (.. % -target -value))}]
(if @input-error
[:div.input-error {:style {:color "red" :margin-top 5}}
"Please enter a valid number."])]]]
[:ul.filter-items
(map (fn [item]
^{:key (:id item)}
[:li.filter-item
[:button.button
{:style {:margin 0}
:on-click (fn [event] (swap! filter-items #(remove (comp (partial = (:query item)) :query) %)))}
(:filter-type item) ": " [:span.filter-item-string (:query item)]]])
@filter-items)]]
[components/autoscroll-list {:class "panel-content-scrollable" :scroll? true}
[:table
[:thead>tr
[:th {:style {:padding 0}}
[:button.text-button
{:style {:cursor "pointer"}
:on-click (fn [ev]
;; Always reset expansions
(swap! trace-detail-expansions assoc :overrides {})
;; Then toggle :show-all?
(swap! trace-detail-expansions update :show-all? not))}
(if (:show-all? @trace-detail-expansions) "-" "+")]]
[:button.text-button
{:style {:cursor "pointer"}
:on-click (fn [ev]
;; Always reset expansions
(swap! trace-detail-expansions assoc :overrides {})
;; Then toggle :show-all?
(swap! trace-detail-expansions update :show-all? not))}
(if (:show-all? @trace-detail-expansions) "-" "+")]]
[:th "operations"]
[:th
[:button {:class (str/join " " ["filter-items-count"
(when (pos? (count @filter-items)) "active")])
:on-click #(reset! filter-items [])}
(when (pos? (count @filter-items))
(str (count visible-traces) " of "))
(str (count @traces))]
" events "
(when (pos? (count @traces))
[:span "(" [:button.text-button {:on-click #(do (trace/reset-tracing!) (reset! traces []))} "clear"] ")"])]
[:button {:class (str/join " " ["filter-items-count"
(when (pos? (count @filter-items)) "active")])
:on-click #(reset! filter-items [])}
(when (pos? (count @filter-items))
(str (count visible-traces) " of "))
(str (count @traces))]
" events "
(when (pos? (count @traces))
[:span "(" [:button.text-button {:on-click #(do (trace/reset-tracing!) (reset! traces []))} "clear"] ")"])]
[:th {:style {:text-align "right"}} "meta"]]
[:tbody (render-traces visible-traces filter-items filter-input trace-detail-expansions)]]]]))))
@ -308,13 +308,13 @@
(defn devtools []
;; Add clear button
;; Filter out different trace types
(let [position (r/atom :right)
panel-width% (r/atom (localstorage/get "panel-width-ratio" 0.35))
showing? (r/atom (localstorage/get "show-panel" false))
dragging? (r/atom false)
pin-to-bottom? (r/atom true)
selected-tab (r/atom (localstorage/get "selected-tab" :traces))
window-width (r/atom js/window.innerWidth)
(let [position (r/atom :right)
panel-width% (r/atom (localstorage/get "panel-width-ratio" 0.35))
showing? (r/atom (localstorage/get "show-panel" false))
dragging? (r/atom false)
pin-to-bottom? (r/atom true)
selected-tab (r/atom (localstorage/get "selected-tab" :traces))
window-width (r/atom js/window.innerWidth)
handle-window-resize (fn [e]
;; N.B. I don't think this should be a perf bottleneck.
(reset! window-width js/window.innerWidth))
@ -408,10 +408,10 @@
new-panel))))
(defn inject-styles []
(let [id "--re-frame-trace-styles--"
styles-el (.getElementById js/document id)
(let [id "--re-frame-trace-styles--"
styles-el (.getElementById js/document id)
new-styles-el (.createElement js/document "style")
new-styles styles/panel-styles]
new-styles styles/panel-styles]
(.setAttribute new-styles-el "id" id)
(-> new-styles-el
(.-innerHTML)

View File

@ -29,18 +29,18 @@
(let [expanded? (r/atom false)]
(fn [jsonml]
[:span
{:class (str/join " " ["re-frame-trace--object"
(when @expanded? "expanded")])}
[:span {:class "toggle"
:on-click #(swap! expanded? not)}
[:button.expansion-button (if @expanded? "▼" "▶")]]
(jsonml->hiccup (if @expanded?
(cljs-devtools/body-api-call
(.-object (get jsonml 1))
(.-config (get jsonml 1)))
(cljs-devtools/header-api-call
(.-object (get jsonml 1))
(.-config (get jsonml 1)))))])))
{:class (str/join " " ["re-frame-trace--object"
(when @expanded? "expanded")])}
[:span {:class "toggle"
:on-click #(swap! expanded? not)}
[:button.expansion-button (if @expanded? "▼" "▶")]]
(jsonml->hiccup (if @expanded?
(cljs-devtools/body-api-call
(.-object (get jsonml 1))
(.-config (get jsonml 1)))
(cljs-devtools/header-api-call
(.-object (get jsonml 1))
(.-config (get jsonml 1)))))])))
(defn jsonml->hiccup
"JSONML is the format used by Chrome's Custom Object Formatters.
@ -52,72 +52,72 @@
[jsonml]
(if (number? jsonml)
jsonml
(let [[head & args] jsonml
tagnames #{"div" "span" "ol" "li" "table" "tr" "td"}]
(let [[head & args] jsonml
tagnames #{"div" "span" "ol" "li" "table" "tr" "td"}]
(cond
(contains? tagnames head) (let [[style & children] args]
(into
[(keyword head) {:style (-> (js->clj style)
(get "style")
(string->css))}]
(map jsonml->hiccup children)))
(contains? tagnames head) (let [[style & children] args]
(into
[(keyword head) {:style (-> (js->clj style)
(get "style")
(string->css))}]
(map jsonml->hiccup children)))
(= head "object") [data-structure jsonml]
(= jsonml ", ") " "
(= head "object") [data-structure jsonml]
(= jsonml ", ") " "
:else jsonml))))
(defn subtree [data title]
(let [expanded? (r/atom false)]
(fn [data]
[:div
{:class (str/join " " ["re-frame-trace--object"
(when @expanded? "expanded")])}
[:span {:class "toggle"
:on-click #(swap! expanded? not)}
[:button.expansion-button (if @expanded? "▼ " "▶ ")]]
(or title "data")
[:div {:style {:margin-left 20}}
(cond
(and @expanded?
(or (string? data)
(number? data))) [:div {:style {:margin "10px 0"}} data]
@expanded? (jsonml->hiccup (cljs-devtools/header-api-call data config)))]])))
{:class (str/join " " ["re-frame-trace--object"
(when @expanded? "expanded")])}
[:span {:class "toggle"
:on-click #(swap! expanded? not)}
[:button.expansion-button (if @expanded? "▼ " "▶ ")]]
(or title "data")
[:div {:style {:margin-left 20}}
(cond
(and @expanded?
(or (string? data)
(number? data))) [:div {:style {:margin "10px 0"}} data]
@expanded? (jsonml->hiccup (cljs-devtools/header-api-call data config)))]])))
(defn render-state [data]
(let [subtree-input (r/atom "")
subtree-paths (r/atom (localstorage/get "subtree-paths" #{}))
input-error (r/atom false)]
(defn render-state [data]
(let [subtree-input (r/atom "")
subtree-paths (r/atom (localstorage/get "subtree-paths" #{}))
input-error (r/atom false)]
(add-watch subtree-paths
:update-localstorage
(fn [_ _ _ new-state]
(localstorage/save! "subtree-paths" new-state)))
(fn []
[:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}
[:div.panel-content-scrollable {:style {:margin 10}}
[:div.filter-control-input
[components/search-input {:placeholder ":path :into :app-state"
:on-save (fn [path]
(if false ;; TODO check if path exists
(reset! input-error true)
(do
; (reset! input-error false)
;; TODO check if input already wrapped in braces
(swap! subtree-paths #(into #{(cljs.reader/read-string (str "[" path "]"))} %)))))
:on-change #(reset! subtree-input (.. % -target -value))}]]
; (if @input-error
; [:div.input-error {:style {:color "red" :margin-top 5}}
; "Please enter a valid path."])]]
[:div.panel-content-scrollable {:style {:margin 10}}
[:div.filter-control-input
[components/search-input {:placeholder ":path :into :app-state"
:on-save (fn [path]
(if false ;; TODO check if path exists
(reset! input-error true)
(do
; (reset! input-error false)
;; TODO check if input already wrapped in braces
(swap! subtree-paths #(into #{(cljs.reader/read-string (str "[" path "]"))} %)))))
:on-change #(reset! subtree-input (.. % -target -value))}]]
; (if @input-error
; [:div.input-error {:style {:color "red" :margin-top 5}}
; "Please enter a valid path."])]]
[:div.subtrees {:style {:margin "20px 0"}}
(doall
(map (fn [path]
^{:key path}
[:div.subtree-wrapper {:style {:margin "10px 0"}}
[:div.subtree
[subtree
(get-in @data path)
[:button.subtree-button {:on-click #(swap! subtree-paths disj path)}
[:span.subtree-button-string
(str path)]]]]])
[:div.subtrees {:style {:margin "20px 0"}}
(doall
(map (fn [path]
^{:key path}
[:div.subtree-wrapper {:style {:margin "10px 0"}}
[:div.subtree
[subtree
(get-in @data path)
[:button.subtree-button {:on-click #(swap! subtree-paths disj path)}
[:span.subtree-button-string
(str path)]]]]])
@subtree-paths))]
[subtree @data [:span.label "app-db"]]]])))
[subtree @data [:span.label "app-db"]]]])))

View File

@ -57,7 +57,7 @@
:r r
:data trace
:fx 350}))
(remove #(nil? (:id %))) ;; remove reactions that are null (mostly from input fields???)
(remove #(nil? (:id %))) ;; remove reactions that are null (mostly from input fields???)
(distinct-k :id)))
;; Use http://bl.ocks.org/GerHobbelt/3683278 to constrain nodes
@ -71,9 +71,9 @@
set)
sub-nodes (select-sub-nodes traces :sub/create disposed-ids 10)
view-nodes nil #_ (select-view-nodes traces :render unmounted-components 5)
view-nodes nil #_(select-view-nodes traces :render unmounted-components 5)
sub-links (select-links traces :sub/run disposed-ids 1)
view-links nil #_ (select-links traces :render unmounted-components 0.5)
view-links nil #_(select-links traces :render unmounted-components 0.5)
all-nodes (concat extra-nodes sub-nodes view-nodes)
node-ids (set (map :id all-nodes))
nodes-links (->> (mapcat (fn [{:keys [source target]}] [source target]) view-links) set)

View File

@ -166,9 +166,9 @@
(attr "opacity" 0))
_ (.. node-exit-t
(on "end" (fn [] (this-as this
(.. js/d3
(select this)
(remove))))))
(.. js/d3
(select this)
(remove))))))
_ (.. node-exit-t
(transition)
(call (fn []