Last active
April 12, 2022 07:48
-
-
Save borkdude/eede232a968a39b256872c5262b12322 to your computer and use it in GitHub Desktop.
Reagent ratom / reaction
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
(require '[promesa.core :as p] | |
'[reagent.ratom :as ratom]) | |
(def app-state (ratom/atom {:state-var-1 {:var-a 2 | |
:var-b 3} | |
:state-var-2 {:var-a 7 | |
:var-b 9}})) | |
(def app-var2a-reaction (ratom/make-reaction | |
#(get-in @app-state [:state-var-2 :var-a]))) | |
(defn foo [] | |
(prn @app-var2a-reaction)) | |
(ratom/track! foo) | |
(p/let [_ (p/delay 1000)] | |
(swap! app-state update-in [:state-var-2 :var-a] inc) | |
(p/delay 1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment