Skip to content

Commit afa452b

Browse files
committed
working unstrument
1 parent 7bae582 commit afa452b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/main/cljs/cljs/spec.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,11 @@
365365
`(when-let [checked# (cljs.spec/instrument* ~v)]
366366
(set! ~sym checked#)
367367
~v)))
368+
369+
(defmacro unstrument
370+
"Undoes instrument on the var at v, a var or symbol. Idempotent."[v]
371+
(let [v (if-not (seq? v) (list 'var v) v)
372+
sym (second v)]
373+
`(when-let [raw# (cljs.spec/unstrument* ~v)]
374+
(set! ~sym raw#)
375+
~v)))

src/main/cljs/cljs/spec.cljs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,16 @@
331331
checked))))
332332
(throw (no-fn-specs v specs)))))
333333

334-
;(defn unstrument
335-
; "Undoes instrument on the var at v, a var or symbol. Idempotent."
336-
; [v]
337-
; (let [v (->var v)]
338-
; (locking instrumented-vars
339-
; (when-let [{:keys [raw wrapped]} (get @instrumented-vars v)]
340-
; (let [current @v]
341-
; (when (= wrapped current)
342-
; (alter-var-root v (constantly raw))))
343-
; (swap! instrumented-vars dissoc v))
344-
; v)))
345-
;
334+
(defn unstrument*
335+
[v]
336+
(locking instrumented-vars
337+
(when-let [{:keys [raw wrapped]} (get @instrumented-vars v)]
338+
(let [current @v]
339+
(when (= wrapped current)
340+
raw))
341+
(swap! instrumented-vars dissoc v))
342+
v))
343+
346344
;(defn speced-vars
347345
; "Returns the set of vars whose namespace is in ns-syms AND
348346
;whose vars have been speced with fdef. If no ns-syms are

0 commit comments

Comments
 (0)