   (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

  (clean [this key]
    (.removeFWatch this key)
    (.removeInvalidationWatch this key)
    (when (identical? 0 (.-watchers this)) (identical? 0 (.-iwatchers this))
          ;; (println "cleaning" (.-id this) key)
          (goog.object/forEach (.-deps (.-invalidate this))
                               (fn [val key obj]
                                 (val)
                                 (js-delete obj key)))
          (set! (.-dirty this) true)))
  

  ([x] (ReactiveAtom. (new-reactive-id )x nil nil nil #js {} 0))
  ([x & {:keys [meta validator]}] (ReactiveAtom. (new-reactive-id) x meta validator nil #js {} 0)))

;; (defn- make-invalidate-fn [reactive id]
;;   (let [invalidate-fn
;;         (fn invalidate []
;;           (when-not (.-dirty reactive)
;;             (set! (.-dirty reactive) true)
;;             (if (> (.-watchers reactive) 0)
;;               ;; updates state and notifies watches
;;               (when (.compute reactive)
;;                 (.notifyInvalidationWatches reactive))
;;               ;; updates only invalidation watches
;;               (.notifyInvalidationWatches reactive))))]
;;     (set! (.-id invalidate-fn) id)
;;     (set! (.-deps invalidate-fn) #js {})
;;     invalidate-fn))

(defn- make-register-dep [rx]
  (fn do-register-dep [dep id binding-info]
    (when *trace-capture* (*trace-capture* dep))
    (aset (.-deps rx) id #js [dep binding-info])
    ;; (println "cur deps:" (.-deps rx))
    ((.-add-watch binding-info)
     dep (.-id rx)
     (fn []
