Skip to content

Instantly share code, notes, and snippets.

@abhi18av
Forked from alehatsman/async.cljs
Created August 27, 2019 09:32
Show Gist options
  • Save abhi18av/8b96961f9810cff48575d50f554ab6da to your computer and use it in GitHub Desktop.
Save abhi18av/8b96961f9810cff48575d50f554ab6da 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