Skip to content

Commit a28b4ef

Browse files
committed
add remaining instrument/unstrument helpers
1 parent abc47fc commit a28b4ef

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

src/main/cljs/cljs/spec.clj

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,26 @@
274274

275275
(def ^:private _speced_vars (atom #{}))
276276

277+
(defn speced-vars*
278+
([]
279+
(speced-vars* nil))
280+
([ns-syms]
281+
(let [ns-match? (if (seq ns-syms)
282+
(set ns-syms)
283+
(constantly true))]
284+
(reduce
285+
(fn [ret sym]
286+
(if (ns-match? (namespace sym))
287+
(conj ret (list 'var sym))
288+
ret))
289+
#{} @_speced_vars))))
290+
277291
(defmacro speced-vars
278292
"Returns the set of vars whose namespace is in ns-syms AND
279293
whose vars have been speced with fdef. If no ns-syms are
280294
specified, return speced vars from all namespaces."
281295
[& ns-syms]
282-
(let [ns-match? (if (seq ns-syms)
283-
(set ns-syms)
284-
(constantly true))]
285-
(reduce
286-
(fn [ret sym]
287-
(if (ns-match? (namespace sym))
288-
(conj ret (list 'var sym))
289-
ret))
290-
#{} @_speced_vars)))
296+
(speced-vars* ns-syms))
291297

292298
(defmacro fdef
293299
"Takes a symbol naming a function, and one or more of the following:
@@ -391,3 +397,29 @@ specified, return speced vars from all namespaces."
391397
`(when-let [raw# (cljs.spec/unstrument* ~v)]
392398
(set! ~sym raw#)
393399
~v)))
400+
401+
(defmacro instrument-ns
402+
"Call instrument for all speced-vars in namespaces named
403+
by ns-syms. Idempotent."
404+
[& ns-syms]
405+
`(do
406+
~@(map #(list 'cljs.spec/instrument %) (speced-vars* ns-syms))))
407+
408+
(defmacro unstrument-ns
409+
"Call unstrument for all speced-vars in namespaces named
410+
by ns-syms. Idempotent."
411+
[& ns-syms]
412+
`(do
413+
~@(map #(list 'cljs.spec/unstrument %) (speced-vars* ns-syms))))
414+
415+
(defmacro instrument-all
416+
"Call instrument for all speced-vars. Idempotent."
417+
[]
418+
`(do
419+
~@(map #(list 'cljs.spec/instrument %) (speced-vars*))))
420+
421+
(defmacro unstrument-all
422+
"Call unstrument for all speced-vars. Idempotent"
423+
[]
424+
`(do
425+
~@(map #(list 'cljs.spec/unstrument %) (speced-vars*))))

src/main/cljs/cljs/spec.cljs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -341,38 +341,6 @@
341341
(swap! instrumented-vars dissoc v))
342342
v))
343343

344-
;(defn instrument-ns
345-
; "Call instrument for all speced-vars in namespaces named
346-
;by ns-syms. Idempotent."
347-
; [& ns-syms]
348-
; (when (seq ns-syms)
349-
; (locking instrumented-vars
350-
; (doseq [v (apply speced-vars ns-syms)]
351-
; (instrument v)))))
352-
;
353-
;(defn unstrument-ns
354-
; "Call unstrument for all speced-vars in namespaces named
355-
;by ns-syms. Idempotent."
356-
; [& ns-syms]
357-
; (when (seq ns-syms)
358-
; (locking instrumented-vars
359-
; (doseq [v (apply speced-vars ns-syms)]
360-
; (unstrument v)))))
361-
;
362-
;(defn instrument-all
363-
; "Call instrument for all speced-vars. Idempotent."
364-
; []
365-
; (locking instrumented-vars
366-
; (doseq [v (speced-vars)]
367-
; (instrument v))))
368-
;
369-
;(defn unstrument-all
370-
; "Call unstrument for all speced-vars. Idempotent"
371-
; []
372-
; (locking instrumented-vars
373-
; (doseq [v (speced-vars)]
374-
; (unstrument v))))
375-
376344
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; impl ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
377345
(defn- recur-limit? [rmap id path k]
378346
(c/and (> (get rmap id) (::recursion-limit rmap))

0 commit comments

Comments
 (0)