Skip to content

Commit

Permalink
Better error reporting on missing page data key, added toggle helper
Browse files Browse the repository at this point in the history
  • Loading branch information
zk committed Mar 5, 2013
1 parent 03d0693 commit aa7b231
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cljs/nsfw/util.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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.