-
Notifications
You must be signed in to change notification settings - Fork 204
/
dev.clj
35 lines (33 loc) · 1.49 KB
/
dev.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns malli.dev
(:require [malli.core :as m]
[malli.instrument :as mi]
[malli.clj-kondo :as clj-kondo]))
(defn stop!
"Stops instrumentation for all functions vars and removes clj-kondo type annotations."
[]
(remove-watch @#'m/-function-schemas* ::watch)
(mi/unstrument!)
(clj-kondo/save! {})
(println "stopped instrumentation"))
(defn start!
"Collects defn schemas from all loaded namespaces and starts instrumentation for
a filtered set of function Vars (e.g. `defn`s). See [[malli.core/-instrument]]
for possible options. Re-instruments if the function schemas change. Also emits
clj-kondo type annotations."
([] (start! nil))
([options]
(with-out-str (stop!))
(mi/collect! {:ns (all-ns)})
(let [watch (fn [_ _ old new]
(mi/instrument! (assoc options :data (->> (for [[n d] new
:let [no (get old n)]
[s d] d
:when (not= d (get no s))]
[[n s] d])
(into {})
(reduce-kv assoc-in {}))))
(clj-kondo/emit!))]
(add-watch @#'m/-function-schemas* ::watch watch))
(mi/instrument! options)
(clj-kondo/emit!)
(println "started instrumentation")))