Permalink
Browse files

Add blind!

  • Loading branch information...
cmeiklejohn committed Mar 13, 2013
1 parent deaf858 commit b160cd38ed3279b50c04d7df28f16cc9cf93bb4d
Showing with 17 additions and 3 deletions.
  1. +1 −1 README.md
  2. +16 −2 src/cljs/shafty/core.cljs
View
@@ -48,7 +48,7 @@ delayE | delay!
snapshotE | snapshot!
filterRepeatsE | filter-repeats!
calmE | calm!
-blindE |
+blindE | blind!
timerE | timer!
## TODO
View
@@ -69,6 +69,7 @@
(once! [this])
(delay! [this interval])
(calm! [this interval])
+ (blind! [this interval])
(merge! [this that])
(filter! [this filter-fn])
(collect! [this init combine-fn])
@@ -173,7 +174,9 @@
false)))))
(delay! [this interval]
- (let [f (fn [me x] (js/setTimeout (fn [] (.-value x)) interval))
+ (let [f (fn [me x] (js/setTimeout
+ (fn [] (.-value x)) interval)
+ shafty.core.Event/SENTINEL)
e (event [this] f)]
(add-sink! this e) e))
@@ -185,7 +188,18 @@
(if (nil? t)
(js/setTimeout (fn []
(swap! t (fn [] nil))
- (.-value acc)) interval)))
+ (.-value acc)) interval))
+ shafty.core.Event/SENTINEL)
+ e (event [this] f)]
+ (add-sink! this e) e))
+
+ (blind! [this interval]
+ (let [last-sent (atom nil)
+ f (fn [me x] (let [current-time (js/Date.)]
+ (if (> (- current-time last-sent) interval)
+ (do
+ (swap! last-sent (fn [] current-time)) (.-value x))
+ (shafty.core.Event/SENTINEL))))
e (event [this] f)]
(add-sink! this e) e))

0 comments on commit b160cd3

Please sign in to comment.