Created
June 20, 2015 02:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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