Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add clear-hooks function. Closes #1.

  • Loading branch information...
commit 8a124da5e5888e0dac7d7df16f0f1b4d1d634fdf 1 parent 14275f2
@technomancy authored
Showing with 13 additions and 3 deletions.
  1. +13 −3 src/robert/hooke.clj
View
16 src/robert/hooke.clj
@@ -62,6 +62,11 @@
(prepare-for-hooks target-var)
(swap! (:robert.hooke/hook (meta @target-var)) add-unless-present f))
+(defn- clear-hook-mechanism [target-var]
+ (alter-var-root target-var
+ (constantly (:robert.hooke/original
+ (meta @target-var)))))
+
(defn remove-hook
"Remove hook function f from target-var."
[target-var f]
@@ -69,9 +74,14 @@
(swap! (:robert.hooke/hook (meta @target-var))
(partial remove #{f}))
(when (empty? @(:robert.hooke/hook (meta @target-var)))
- (alter-var-root target-var
- (constantly (:robert.hooke/original
- (meta @target-var)))))))
+ (clear-hook-mechanism target-var))))
+
+(defn clear-hooks
+ "Remove hook function f from target-var."
+ [target-var]
+ (swap! (:robert.hooke/hook (meta @target-var)) empty)
+ (when (empty? @(:robert.hooke/hook (meta @target-var)))
+ (clear-hook-mechanism target-var)))
(defmacro prepend [target-var & body]
`(add-hook (var ~target-var) (fn [f# & args#]
Please sign in to comment.
Something went wrong with that request. Please try again.