            (fn [{:syms [?a ?super ?b]}] [[?a ?super ?b]]))
         pq (:qvar-result (add-param-query! g :pq '[?s knows ?o]))
         jq (:qvar-result (add-join-query! g '[[?p author ?prj] [?prj type project] [?p type person]]))
-        tq (:qvar-result (add-join-query! g '[[?p author ?prj] [?prj tag ?t]]))
-        _ (run!
-           #(add-triple! g %)
-           '[[toxi author fabric]
-             [fabric type project]
-             [knows type symmetric-prop]
-             [knows domain person]
-             [author domain person]
-             [author range creative-work]
-             [parent sub-prop-of ancestor]
-             [ancestor type transitive-prop]
-             [ancestor domain person]
-             [ancestor range person]])
-        ;;_ (prn :next-id (-> g :g :state deref :next-id))
-        ctx (f/async-execution-context {:graph g})
+        tq (:qvar-result (add-join-query! g '[[?p author ?prj] [?prj tag ?t]]))]
+    (run!
+     #(add-triple! g %)
+     '[[toxi author fabric]
+       [fabric type project]
+       [knows type symmetric-prop]
+       [knows domain person]
+       [author domain person]
+       [author range creative-work]
+       [parent sub-prop-of ancestor]
+       [ancestor type transitive-prop]
+       [ancestor domain person]
+       [ancestor range person]])
+    {:g            g
+     :log          log
+     :all          all
+     :toxi         toxi
+     :types        types
+     :knows        knows
+     :projects     projects
+     :pq           pq
+     :jq           jq
+     :tq           tq
+     :num-projects num-projects
+     :num-types    num-types}))
+
+(defn ^:export start-async
+  []
+  (let [spec     (make-test-graph)
+        {:keys [g log all pq jq tq]} spec
+        ctx      (f/async-execution-context {:graph g})
         ctx-chan (f/execute! ctx)]
-    (go []
+    (go
+      (let [res (<! ctx-chan)]
+        (warn :result res)
+        (warn (sort @all))
+        (run!
+         #(add-triple! g %)
+         '[[toxi parent noah]
+           [ingo parent toxi]
+           [geom type project]
+           [toxi author geom]
+           [toxi knows noah]
+           [geom tag clojure]
+           [fabric tag clojure]])
         (let [res (<! ctx-chan)]
           (warn :result res)
-          (warn (sort @all))
-          (run!
-           #(add-triple! g %)
-           '[[toxi parent noah]
-             [ingo parent toxi]
-             [geom type project]
-             [toxi author geom]
-             [toxi knows noah]
-             [geom tag clojure]
-             [fabric tag clojure]])
+          (warn :all (sort @all))
+          (warn :pq @pq)
+          (warn :jq @jq)
+          (warn :tq @tq)
+          (remove-triple! g '[geom tag clojure])
+          (remove-triple! g '[fabric tag clojure])
           (let [res (<! ctx-chan)]
-            (warn :result res)
-            (warn :all (sort @all))
-            (warn :pq @pq)
             (warn :jq @jq)
             (warn :tq @tq)
-            (remove-triple! g '[geom tag clojure])
-            (remove-triple! g '[fabric type project])
-            (let [res (<! ctx-chan)]
-              (warn :jq @jq)
-              (warn :tq @tq)
-              (f/stop! ctx)
-              (do (remove-triple-graph-logger log)
-                  (warn :done))))))
-
-    {:g        g
-     :ctx      ctx
-     :all      all
-     :toxi     toxi
-     :types    types
-     :knows    knows
-     :projects projects
-     :pq       pq
-     :jq       jq
-     :tq       tq
-     :num-projects num-projects
-     :num-types num-types
-     }))
+            (f/stop! ctx)
+            (do (remove-triple-graph-logger log)
+                (warn :done))))))
+    (assoc spec :ctx ctx)))
 
 
 (defn ^:export start-sync
   []
-  (let [;;log (add-triple-graph-logger "triple-log.edn")
-        ;;g (triple-graph (f/logged-compute-graph (f/compute-graph) log))
-        g (triple-graph (f/compute-graph))
-        log (add-triple-graph-logger
-             g #?(:clj
-                  #(spit "triple-log.edn" (str (pr-str %) "\n") :append true)
-                  :cljs
-                  #(.log js/console (pr-str %))))
-        toxi (:result (add-query! g :toxi ['toxi nil nil]))
-        types (:result (add-query! g :types [nil 'type nil]))
-        projects (:result (add-query! g :projects [nil 'type 'project]))
-        knows (:result (add-query! g :projects [nil 'knows nil]))
-        all (:result (add-query! g :all [nil nil nil]))
-        num-projects (add-counter! g projects)
-        num-types (add-counter! g types)
-        _ (add-rule!
-           g :symmetric '[[?a ?prop ?b] [?prop type symmetric-prop]]
-           (fn [{:syms [?a ?prop ?b]}] [[?b ?prop ?a]]))
-        _ (add-rule!
-           g :domain '[[?a ?prop nil] [?prop domain ?d]]
-           (fn [{:syms [?a ?prop ?d]}] [[?a 'type ?d]]))
-        _ (add-rule!
-           g :range '[[nil ?prop ?a] [?prop range ?r]]
-           (fn [{:syms [?a ?prop ?r]}] [[?a 'type ?r]]))
-        _ (add-rule!
-           g :transitive '[[?a ?prop ?b] [?b ?prop ?c] [?prop type transitive-prop]]
-           (fn [{:syms [?a ?prop ?c]}] [[?a ?prop ?c]]))
-        _ (add-rule!
-           g :sub-prop '[[?a ?prop ?b] [?prop sub-prop-of ?super]]
-           (fn [{:syms [?a ?super ?b]}] [[?a ?super ?b]]))
-        pq (:qvar-result (add-param-query! g :pq '[?s knows ?o]))
-        jq (:qvar-result (add-join-query! g '[[?p author ?prj] [?prj type project] [?p type person]]))
-        tq (:qvar-result (add-join-query! g '[[?p author ?prj] [?prj tag ?t]]))
-        _ (run!
-           #(add-triple! g %)
-           '[[toxi author fabric]
-             [fabric type project]
-             [knows type symmetric-prop]
-             [knows domain person]
-             [author domain person]
-             [author range creative-work]
-             [parent sub-prop-of ancestor]
-             [ancestor type transitive-prop]
-             [ancestor domain person]
-             [ancestor range person]
-             ;;[noah knows toxi]
-             ])
-        ctx (f/sync-execution-context {:graph g})
-        res (f/execute! ctx)]
+  (let [spec (make-test-graph)
+        {:keys [g log all pq jq tq]} spec
+        ctx  (f/sync-execution-context {:graph g})
+        res  (f/execute! ctx)]
     (warn :result res)
     (warn (sort @all))
     (run!

  (query-result [_ id]))

(defn signal-triple
  [vertex op]
  (let [sig [op (:id vertex) @vertex]]
    (debug :signal-triple sig)
    sig))

(defn collect-index
  [spo]
  (f/collect-pure
   (fn [val incoming]
     (debug :update-index spo incoming)
     (debug :old-index val)
     (let [val (transduce
                (map (fn [[op id t]] [op id (nth t spo)]))

       [geom tag clojure]
       [fabric tag clojure]])
    (warn :result2 (f/execute! ctx))
    (warn :all (sort @all))
    (warn :pq @pq)
    (warn :jq @jq)
    (warn :tq @tq)
    (f/signal! (remove-triple! g '[geom tag clojure]) f/sync-vertex-signal)
    (f/signal! (remove-triple! g '[fabric tag clojure]) f/sync-vertex-signal)
    (warn :result3 (f/execute! ctx))
    (warn :all @all)
    (warn :jq @jq)
    (warn :tq @tq)
    (remove-triple-graph-logger log)
    (assoc spec :ctx ctx)))
