Permalink
Browse files

Better error reporting on missing page data key, added toggle helper

  • Loading branch information...
1 parent 03d0693 commit aa7b231d04a215576732b9660670a5b2774218bc @zk committed Mar 5, 2013
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/cljs/nsfw/util.cljs
View
@@ -35,11 +35,21 @@
(gensym))
(defn page-data [key]
- (reader/read-string (aget js/window (str/replace (name key) #"-" "_"))))
+ (try
+ (reader/read-string (aget js/window (str/replace (name key) #"-" "_")))
+ (catch js/Error e
+ (throw (str "Couldn't find page data " key)))))
(defn run-once [f]
(let [did-run (atom false)]
(fn [& args]
(when-not @did-run
(reset! did-run true)
- (apply f args)))))
+ (apply f args)))))
+
+(defn toggle [f0 f1]
+ (let [!a (atom false)]
+ (fn [& args]
+ (let [res (if-not @!a (apply f0 args) (apply f1 args))]
+ (swap! !a not)
+ res))))

0 comments on commit aa7b231

Please sign in to comment.