mirror of
https://github.com/penpot/penpot.git
synced 2025-06-13 19:31:38 +02:00
♻️ Moved debug utils to debug
namespace
This commit is contained in:
parent
7dffddd437
commit
2a11e9962d
7 changed files with 216 additions and 206 deletions
|
@ -1,95 +0,0 @@
|
|||
(ns app.util.debug
|
||||
"Debugging utils"
|
||||
(:require
|
||||
[app.common.math :as mth]
|
||||
[app.util.object :as obj]
|
||||
[app.util.timers :as timers]
|
||||
[cljs.pprint :refer [pprint]]))
|
||||
|
||||
(def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center :export :import #_:simple-selection})
|
||||
|
||||
;; These events are excluded when we activate the :events flag
|
||||
(def debug-exclude-events
|
||||
#{:app.main.data.workspace.notifications/handle-pointer-update
|
||||
:app.main.data.workspace.selection/change-hover-state})
|
||||
|
||||
(defonce ^:dynamic *debug* (atom #{#_:events}))
|
||||
|
||||
(defn debug-all! [] (reset! *debug* debug-options))
|
||||
(defn debug-none! [] (reset! *debug* #{}))
|
||||
(defn debug! [option] (swap! *debug* conj option))
|
||||
(defn -debug! [option] (swap! *debug* disj option))
|
||||
|
||||
(defn ^:export ^boolean debug?
|
||||
[option]
|
||||
(if *assert*
|
||||
(boolean (@*debug* option))
|
||||
false))
|
||||
|
||||
(defn ^:export toggle-debug [name] (let [option (keyword name)]
|
||||
(if (debug? option)
|
||||
(-debug! option)
|
||||
(debug! option))))
|
||||
(defn ^:export debug-all [] (debug-all!))
|
||||
(defn ^:export debug-none [] (debug-none!))
|
||||
|
||||
(defn ^:export tap
|
||||
"Transducer function that can execute a side-effect `effect-fn` per input"
|
||||
[effect-fn]
|
||||
|
||||
(fn [rf]
|
||||
(fn
|
||||
([] (rf))
|
||||
([result] (rf result))
|
||||
([result input]
|
||||
(effect-fn input)
|
||||
(rf result input)))))
|
||||
|
||||
(defn ^:export logjs
|
||||
([str] (tap (partial logjs str)))
|
||||
([str val]
|
||||
(js/console.log str (clj->js val))
|
||||
val))
|
||||
|
||||
(when (exists? js/window)
|
||||
(set! (.-dbg ^js js/window) clj->js)
|
||||
(set! (.-pp ^js js/window) pprint))
|
||||
|
||||
|
||||
(defonce widget-style "
|
||||
background: black;
|
||||
bottom: 10px;
|
||||
color: white;
|
||||
height: 20px;
|
||||
padding-left: 8px;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
width: 40px;
|
||||
z-index: 99999;
|
||||
opacity: 0.5;
|
||||
")
|
||||
|
||||
(defn ^:export fps
|
||||
"Adds a widget to keep track of the average FPS's"
|
||||
[]
|
||||
(let [last (volatile! (.now js/performance))
|
||||
avg (volatile! 0)
|
||||
node (-> (.createElement js/document "div")
|
||||
(obj/set! "id" "fps")
|
||||
(obj/set! "style" widget-style))
|
||||
body (obj/get js/document "body")
|
||||
|
||||
do-thing (fn do-thing []
|
||||
(timers/raf
|
||||
(fn []
|
||||
(let [cur (.now js/performance)
|
||||
ts (/ 1000 (* (- cur @last)))
|
||||
val (+ @avg (* (- ts @avg) 0.1))]
|
||||
|
||||
(obj/set! node "innerText" (mth/precision val 0))
|
||||
(vreset! last cur)
|
||||
(vreset! avg val)
|
||||
(do-thing)))))]
|
||||
|
||||
(.appendChild body node)
|
||||
(do-thing)))
|
Loading…
Add table
Add a link
Reference in a new issue