-
-
Save kanwei/7ac7efc9d966a2416c67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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