Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add calm!

  • Loading branch information...
commit deaf8584692529f0524d9f1014a39420df99ef63 1 parent 89fae58
@cmeiklejohn authored
Showing with 12 additions and 1 deletion.
  1. +1 −1  README.md
  2. +11 −0 src/cljs/shafty/core.cljs
View
2  README.md
@@ -47,7 +47,7 @@ switchE | | calmB |
delayE | delay!
snapshotE | snapshot!
filterRepeatsE | filter-repeats!
-calmE |
+calmE | calm!
blindE |
timerE | timer!
View
11 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]
Please sign in to comment.
Something went wrong with that request. Please try again.