Skip to content

Instantly share code, notes, and snippets.

@danevans
Created June 20, 2015 02:51
Show Gist options
  • Save danevans/94f39df007198c0500f2 to your computer and use it in GitHub Desktop.
Save danevans/94f39df007198c0500f2 to your computer and use it in GitHub Desktop.
Clojurescript function which takes a function as an argument and returns a debounced version of the function. Inspired by http://underscorejs.org/#debounce
(ns util.core
(:import [goog Delay]))
(defn debounce [f interval]
(let [timeout (atom nil)]
(fn [& args]
(when-not (nil? @timeout)
(.disposeInternal @timeout))
(reset! timeout (Delay. #(apply f args)))
(.start @timeout interval))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment