From deaf8584692529f0524d9f1014a39420df99ef63 Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Tue, 12 Mar 2013 20:46:03 -0400 Subject: [PATCH] Add calm! --- README.md | 2 +- src/cljs/shafty/core.cljs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dff0ce3..5d41520 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ switchE | | calmB | delayE | delay! snapshotE | snapshot! filterRepeatsE | filter-repeats! -calmE | +calmE | calm! blindE | timerE | timer! diff --git a/src/cljs/shafty/core.cljs b/src/cljs/shafty/core.cljs index 9836aca..bf3298d 100644 --- a/src/cljs/shafty/core.cljs +++ b/src/cljs/shafty/core.cljs @@ -68,6 +68,7 @@ (bind! [this value-fn]) (once! [this]) (delay! [this interval]) + (calm! [this interval]) (merge! [this that]) (filter! [this filter-fn]) (collect! [this init combine-fn]) @@ -176,6 +177,16 @@ e (event [this] f)] (add-sink! this e) e)) + (calm! [this interval] + (let [acc (atom nil) + t (atom nil) + f (fn [me x] + (swap! acc (fn [] x)) + (if (nil? t) + (js/setTimeout (fn [] + (swap! t (fn [] nil)) + (.-value acc)) interval))) + e (event [this] f)] (add-sink! this e) e)) (merge! [this that]