Created
August 8, 2018 09:55
-
-
Save alehatsman/4e7f8014e370072747702ac7cfb4171e to your computer and use it in GitHub Desktop.
ClojureScript throttle and debouce functions
This file contains hidden or 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