   ([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-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
-          (fn []
-            ((or (.-clean-watch binding-info)
-                 (.-remove-watch binding-info))
-             dep (.-id rx))))
+    (aset (.-deps rx) id #js [dep binding-info])
+    ;; (println "cur deps:" (.-deps rx))
     ((.-add-watch binding-info)
      dep (.-id rx)
      (fn []

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

  (clean [this key]
    (.removeFWatch this key)
    (.removeInvalidationWatch this key)
    ;; (println "trying to clean" watchers iwatchers deps)
    (when (identical? 0 (.-watchers this)) (identical? 0 (.-iwatchers this))
          ;; (println "cleaning" (.-id this) key deps)
          (goog.object/forEach deps
                               (fn [val key obj]
                                 ;; (println "cleaning:" key val)
                                 (let [dep (aget val 0)
                                       binding-info (aget val 1)]
                                   ((or (.-clean-watch binding-info)
                                        (.-remove-watch binding-info))
                                    dep id))
                                 (js-delete obj key)))
          (set! (.-dirty this) true)))
  
