-
-
Save jbritton/431075d30fcd30b0a9506dfbd88b8504 to your computer and use it in GitHub Desktop.
ClojureScript throttle and debouce functions
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 async | |
(:import [goog.async Throttle Debouncer])) | |
(defn disposable->function [disposable listener interval] | |
(let [disposable-instance (disposable. listener interval)] | |
(fn [& args] | |
(.apply (.-fire disposable-instance) disposable-instance (to-array args))))) | |
(defn throttle [listener interval] | |
(disposable->function Throttle listener interval)) | |
(defn debounce [listener interval] | |
(disposable->function Debouncer listener interval)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment