Skip to content

Instantly share code, notes, and snippets.

@jbritton
Forked from alehatsman/async.cljs
Created September 22, 2020 05:13
Show Gist options
  • Save jbritton/431075d30fcd30b0a9506dfbd88b8504 to your computer and use it in GitHub Desktop.
Save jbritton/431075d30fcd30b0a9506dfbd88b8504 to your computer and use it in GitHub Desktop.
ClojureScript throttle and debouce functions
(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