Advertisement
Guest User

Untitled

a guest
May 30th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. (ns freactive-sandbox.core-test
  2. (:require-macros [freactive.macros :refer [rx]])
  3. (:require [freactive.core :refer [atom cursor]]))
  4.  
  5. (enable-console-print!)
  6.  
  7. (def x (atom {:a 1 :b {:c 2 :d 3}}))
  8.  
  9. (def b (cursor x
  10. (fn [x] (:b x))
  11. (fn [x b] (assoc x :b b))))
  12.  
  13. (def c (cursor b
  14. (fn [x] (:c x))
  15. (fn [x c] (assoc x :c c))))
  16.  
  17. (def cd (cursor b
  18. (fn [x] [(:c x) (:d x)])
  19. (fn [x [c d]] (assoc x :c c
  20. :d d))))
  21.  
  22.  
  23. (add-watch cd :cd (fn [k r o n]
  24. (println "cd" o n)))
  25.  
  26. (def c*d (rx (let [[c d] @cd] (* c d))))
  27. (println "Initial c*d" @c*d)
  28.  
  29. (add-watch c*d :c*d (fn [k r o n]
  30. (println "c*d" o n)))
  31.  
  32. (reset! cd [4 5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement