Skip to content

Instantly share code, notes, and snippets.

@candera
Created May 17, 2016 20:55
Show Gist options
  • Save candera/329f1d4df430bbc15bff97778f950d5e to your computer and use it in GitHub Desktop.
Save candera/329f1d4df430bbc15bff97778f950d5e to your computer and use it in GitHub Desktop.
(let [opacity-ch (async/chan (async/dropping-buffer 1))]
(async/go-loop [last-set (:opacity @app-state)
last-received nil]
(let [t (async/timeout 100)
[ch val] (async/alts! [t opacity-ch])
[new-set new-received] (cond
(= ch opacity-ch)
[last-set val]
(not= last-set last-received)
(do
(swap! app-state assoc :opacity last-received)
[last-received last-received])
:else
[last-set last-received])]
(recur new-set new-received)))
(defn opacity-change
[e]
(let [opacity (-> e .-target .-value (/ 100.0))]
(async/go (>! opacity-ch opacity)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment