Skip to content

Instantly share code, notes, and snippets.

@ioRekz
Last active July 18, 2017 22:04
Show Gist options
  • Select an option

  • Save ioRekz/9492e01e4819a11ce90ea4961a07de33 to your computer and use it in GitHub Desktop.

Select an option

Save ioRekz/9492e01e4819a11ce90ea4961a07de33 to your computer and use it in GitHub Desktop.

Revisions

  1. ioRekz revised this gist Jul 18, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion async.cljs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    (defn slow-counter []
    [:div
    [:div "Current value counter: " @counter]
    [:button {:onClick increment} "Increment with 2s minimum interval"]])
    [:button {:onClick increment} "Increment"]])

    (go
    (while true
  2. ioRekz revised this gist Jul 18, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion async.cljs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    (defn slow-counter []
    [:div
    [:div "Current value counter: " @counter]
    [:button {:onClick #(increment)} "Increment"]])
    [:button {:onClick increment} "Increment with 2s minimum interval"]])

    (go
    (while true
  3. ioRekz revised this gist Jul 18, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions async.cljs
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@
    (go
    (while true
    (<! increment-chan)
    (<! (async/timeout 3000))
    (swap! counter inc)))
    (swap! counter inc)
    (<! (async/timeout 2000))))

    (reagent/render [slow-counter] js/klipse-container)
  4. ioRekz created this gist Jul 18, 2017.
    24 changes: 24 additions & 0 deletions async.cljs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    (require '[reagent.core :as reagent])
    (require '[cljs.core.async :as async :refer [<! >!]])
    (require-macros '[cljs.core.async.macros :refer [go go-loop]])

    (def increment-chan (async/chan))

    (def counter
    (reagent/atom 1))

    (defn increment []
    (async/put! increment-chan 1))

    (defn slow-counter []
    [:div
    [:div "Current value counter: " @counter]
    [:button {:onClick #(increment)} "Increment"]])

    (go
    (while true
    (<! increment-chan)
    (<! (async/timeout 3000))
    (swap! counter inc)))

    (reagent/render [slow-counter] js/klipse-container)