Skip to content

Instantly share code, notes, and snippets.

@sparkofreason
Created April 21, 2015 14:16
Show Gist options
  • Save sparkofreason/a42420c3f9572de5c82d to your computer and use it in GitHub Desktop.
Save sparkofreason/a42420c3f9572de5c82d to your computer and use it in GitHub Desktop.
add-watch on freactive rx expression not working?
(ns freactive-sandbox.core-test
(:require-macros [freactive.macros :refer [rx]])
(:require [freactive.core :refer [atom cursor]]))
(enable-console-print!)
(def x (atom {:a 1 :b {:c 2 :d 3}}))
(def b (cursor x
(fn [x] (:b x))
(fn [x b] (assoc x :b b))))
(def c (cursor b
(fn [x] (:c x))
(fn [x c] (assoc x :c c))))
(def cd (cursor b
(fn [x] [(:c x) (:d x)])
(fn [x [c d]] (assoc x :c c
:d d))))
(add-watch cd :cd (fn [k r o n]
(println "cd" o n)))
(def c*d (rx (let [[c d] @cd] (* c d))))
(println "Initial c*d" @c*d)
(add-watch c*d :c*d (fn [k r o n]
(println "c*d" o n)))
(reset! cd [4 5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment