Skip to content

Instantly share code, notes, and snippets.

@kanwei
Created February 20, 2016 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanwei/7ac7efc9d966a2416c67 to your computer and use it in GitHub Desktop.
Save kanwei/7ac7efc9d966a2416c67 to your computer and use it in GitHub Desktop.
(register-sub :timer (fn [db]
(reaction (:timer @db))))
(register-handler :inc-timer (fn [app-state]
(if-not (:timer app-state)
(assoc app-state :timer [0])
(update-in app-state [:timer] conj (rand-int 100)))))
(js/setInterval #(dispatch [:inc-timer]) 1000)
(defn inner-test []
(reagent/create-class
{:component-will-receive-props (fn [c props]
(println props))
:component-did-mount #(println "mounted")
:component-did-update (fn [c]
(println "updated")
(println (reagent/props c)))
:reagent-render (fn []
[:div])}))
(defn outer-test []
(let [t (subscribe [:timer])]
[:div
[:div (str @t)]
[inner-test @t]]
))
(defcard-rg :timer-test [outer-test])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment