             (apush out-facts fact))))
       (aset node->state node set))))
 
-(defn index-update! [node key-ixes]
-  (fn [node->state in-facts out-facts]
+(defn index-update! [key-ixes]
+  (fn [node node->state in-facts out-facts]
     (let [index (aget node->state node)]
       (dotimes [i (alength in-facts)]
         (let [fact (aget in-facts i)

              (apush out-facts (fact-join-ixes left-fact right-fact val-ixes))))))))

(comment
  (->
   (->FlowState #js [(transient #{})]
                #js [#js [1] #js [0]]
                #js [#js [:a :b "c" :d] #js []]
                #js [(filter-map-update! (fn [x] (when (keyword? x) x))) (union-update! 0)])
   fixpoint)

  (->
   (->FlowState #js [(transient #{})]
                #js [#js [1] #js [0]]
                #js [#js [:a :b "c" :d] #js []]
                #js [(filter-map-update! (fn [x] (when (keyword? x) x))) (union-update! 0)])
   fixpoint
   :node->state
   (aget 0)
   persistent!)

  (deffact edge "[x] has an edge to [y]")
  (deffact connected "[x] is connected to [y]")

  ;; [x] has an edge to [y]
  ;; [y] is connected to [z]
  ;; + [x] is connected to [z]

  ;; TODO use filter-map in here to get the right shape
  (->
   (->
    (->FlowState #js [(transient #{}) (transient #{}) (transient {}) (transient {}) nil]
                 #js [#js [2 7] #js [3] #js [4] #js [5] #js [6] #js [6] #js [3] #js [3]]
                   #js [#js [(->edge 0 1) (->edge 1 2) (->edge 2 3) (->edge 3 1)] #js [] #js [] #js [] #js [] #js [] #js [] #js []]
                   #js [(union-update! 0)
                        (union-update! 1)
                        (index-update! 2 #js [1])
                        (index-update! 3 #js [0])
                        (lookup-update! 3 #js [1] #js [0 3])
                        (lookup-update! 2 #js [0] #js [2 1])
                        (union-update! 1)
                        (union-update! 1)])
    fixpoint)
   :node->state
   (aget 1)
   persistent!)

  )

            (apush out-facts fact))))
      (aset node->state node index))))

(defn lookup-update! [index-node key-ixes val-ixes]
  (fn [node node->state in-facts out-facts]
    (let [index (aget node->state index-node)]
      (dotimes [i (alength in-facts)]
        (let [left-fact (aget in-facts i)
              key (fact-ixes left-fact key-ixes)]
