Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from pauldorman/master

Prevent clear-hooks from throwing exception when no hooks exist for target var.
  • Loading branch information...
commit cc06fea562c065b2efdb33dbf8590b974f277dea 2 parents d2a01a4 + 2d85199
@technomancy authored
Showing with 13 additions and 3 deletions.
  1. +4 −3 src/robert/hooke.clj
  2. +9 −0 test/robert/test_hooke.clj
View
7 src/robert/hooke.clj
@@ -79,9 +79,10 @@
(defn clear-hooks
"Remove all hooks 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)))
+ (when (:robert.hooke/hook (meta @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#]
View
9 test/robert/test_hooke.clj
@@ -31,6 +31,15 @@
(is (= hooked orig-hooked))
(is (hooked))))
+(deftest test-clear-hooks
+ (is (nil? (meta @#'hooked)))
+ (add-hook #'hooked #'asplode)
+ (is (not (nil? (meta @#'hooked))))
+ (clear-hooks #'hooked)
+ (is (nil? (meta @#'hooked)))
+ (is (= nil (clear-hooks #'hooked)))
+ (is (nil? (meta @#'hooked))))
+
(defn print-name [name]
(println name))
Please sign in to comment.
Something went wrong with that request. Please try again.