Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit aa7b231d04a215576732b9660670a5b2774218bc 1 parent 03d0693
@zk authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/cljs/nsfw/util.cljs
View
14 src/cljs/nsfw/util.cljs
@@ -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))))
Please sign in to comment.
Something went wrong with that request. Please try again.