Skip to content

Commit

Permalink
Add calm!
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeiklejohn committed Mar 13, 2013
1 parent 89fae58 commit deaf858
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -47,7 +47,7 @@ switchE | | calmB |
delayE | delay!
snapshotE | snapshot!
filterRepeatsE | filter-repeats!
calmE |
calmE | calm!
blindE |
timerE | timer!

Expand Down
11 changes: 11 additions & 0 deletions src/cljs/shafty/core.cljs
Expand Up @@ -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])
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit deaf858

Please sign in to comment.