Skip to content

Instantly share code, notes, and snippets.

@alehatsman
Created August 8, 2018 09:55
Show Gist options
  • Save alehatsman/4e7f8014e370072747702ac7cfb4171e to your computer and use it in GitHub Desktop.
Save alehatsman/4e7f8014e370072747702ac7cfb4171e 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