         (set! (.-state cursor) new-value)
         (when (> watchers 0)
           (.notifyFWatches cursor old-value new-value))
-        (when-not (> iwatchers 0)
+        (when (> iwatchers 0)
           (.notifyInvalidationWatches cursor))
         new-value)))
   (clean [this key]

  (let [id auto-reactive-id]
    (set! auto-reactive-id (inc auto-reactive-id))
    (str "-r." id)))

(deftype BindingInfo [raw-deref add-watch remove-watch clean-watch])

(defprotocol IReactive
  (-get-binding-fns [this]))

(def ^:dynamic *register-dep* nil)

;; (defn register-dep [dep id binding-info]
;;   (when-let [invalidate *invalidate-rx*]
;;     (when *trace-capture* (*trace-capture* dep))
;;     (aset (.-deps invalidate) id
;;           (fn [key]
;;             ((or (.-clean-watch binding-info)
;;                  (.-remove-watch binding-info))
;;              dep key)))
;;     ((.-add-watch binding-info)
;;      dep (.-id invalidate)
;;      (fn []
;;        ((.-remove-watch binding-info) dep id)
;;        (invalidate)))))

(defn register-dep [dep id binding-info]
  (when-let [rdep *register-dep*]
    (rdep dep id binding-info)))

(def ^:private iwatchable-binding-fns
  (BindingInfo. cljs.core/-deref cljs.core/-add-watch

  (:refer-clojure :exclude [atom])
  (:require [goog.object]))

;; Core API

(deftype BindingInfo [raw-deref add-watch remove-watch clean-watch])

(defprotocol IReactive
  (-get-binding-fns [this]))

(def ^:dynamic *register-dep* nil)

(defn register-dep [dep id binding-info]
  (when-let [rdep *register-dep*]
    (rdep dep id binding-info)))

;; END Core API

(def ^:dynamic *lazy* nil)

