       (event-channel-fn [_] (event-channel-fn node)))))
 
 
-;(defrecord Input
-;  [init event-channel-fn topic])
-
-;(defn async*
-;  [id sig]
-;  (let [s (sprout sig)
-;        c-in (:channel s)
-;        c-out (chan 1 (comp (filter change?)
-;                            (map body)))]
-;    (async/pipe c-in c-out)
-;    (input* id (:value s))))
-;
-;(def async
-;  [source-node]
-;  (let [topic (gen-id)]
-;    (reify
-;      NodeProtocol
-;      (node->signal [_ source-node->signal]
-;        (async* topic (source-node->signal source-node)))
-;      (sources [_] [source-node])
-;      InputNodeProtocol
-;      (event-topic [_] topic)
-;      (event-channel-fn [_] ()))))
-
 (defn lift-msgs
   [f & source-nodes]
   (reify

              (recur (zip/up p)))
          [(zip/node p) :end]))))

(defn output-nodes->dependency-map
  [output-nodes]
  (let []
    (loop [deps {}
           loc (node-graph-zipper output-nodes)]
      (cond
        (zip/end? loc)
          deps
        (contains? deps (zip/node loc))
          (recur deps
                 (skip-subtree loc))
        :else
          (let [n (zip/node loc)]
            (recur (if (sequential? n)
                     deps
                     (assoc deps n (set (sources n))))
                   (zip/next loc)))))))

(defn topsort
  [outputs]
  (-> outputs
      output-nodes->dependency-map
      kahn/kahn-sort
      reverse))



(defn wire-up
  [input-nodes output-node spawned-world signal-map]
  (let [output-sprout (sprout (get signal-map output-node))]
    (tools/concat (async/to-chan [(:value output-sprout)])
                  (async/pipe (:channel output-sprout)
                              (chan 1 (comp (filter change?)
                                            (map body)))))))


(defrecord CompiledGraph
