 
 
 (defn node-graph-zipper
-  [output-nodes]
+  [output-node]
   (zip/zipper (constantly true)
-              (fn [x]
-                (if (sequential? x)
-                  (seq x)
-                  (seq (sources x))))
+              (comp seq sources)
               nil
-              output-nodes))
+              output-node))
 
 (defn skip-subtree
   [loc]

        (recur msg)))
    (->Signal v (async/mult c-out))))

;(defn- channel-input
;  [ch v]
;  (let [id (gen-id)
;        events (async/map (partial vector id) [ch])]
;    (async/pipe events new-event)
;    (input* event-notify id v)))
;
;
;(defn write-port
;  [init]
;  (let [ch (chan 1)
;        sig (channel-input ch init)]
;    (reify
;      impl/Channel
;      (close! [_] (impl/close! ch))
;      (closed? [_] (impl/closed? ch))
;      impl/WritePort
;      (put! [_ val fn1] (impl/put! ch val fn1))
;      SignalProtocol
;      (sprout [_] (sprout sig)))))



;(defn async
;  [sig]
;  (let [s (sprout sig)
;        c-in (:channel s)
;        c-out (chan 1 (comp (filter change?)
;                            (map body)))]
;    (channel-input (async/pipe c-in c-out)
;                   (:value s))))
;
;(defn constant
;  [value]
;  (let [msg (no-change value)
;        out (async/tap event-notify (chan 1 (map (constantly msg))))]
;    (->Signal value (async/mult out))))

;(defn merge
;  [& sigs]
;  (let [sprouts (mapv sprout sigs)
;        first-value (:value (first sprouts))
;        msg-vectors (->> sprouts
;                         (mapv :channel)
;                         (async/map vector))
;        c-out (chan)]
;    (go-loop [prev first-value]
;      (let [msgs (<! msg-vectors)
;            first-change (first (filter change? msgs))
;            msg (or first-change (no-change prev))]
;        (>! c-out msg)
;        (recur (body msg))))
;    (Node. first-value (async/mult c-out))))

;(defn merge
;  [& sigs]
;  (apply lift-msgs*
;         (fn [& msgs]
;           (->> msgs (filter change?) first))
;         sigs))

;(defn sample-on
;  [sampler-sig value-sig]
;  (let [sample-channel (:channel (sprout sampler-sig))
;        {init :value
;         value-channel :channel} (sprout value-sig)
;        c-in (async/map vector [sample-channel value-channel])
;        c-out (chan)]
;    (go-loop []
;      (let [[sample-msg value-msg] (<! c-in)
;            value (body value-msg)
;            msg (if (change? sample-msg)
;                  (change value)
;                  (no-change value))]
;        (>! c-out msg)
;        (recur)))
;    (Node. init (async/mult c-out))))

;(defn sample-on
;  [sampler-sig value-sig]
;  (lift-msgs (fn [sample-msg value-msg]
;               (when (change? sample-msg)
;                 (change (body value-msg))))
;             sampler-sig
;             value-sig))


(defprotocol NodeProtocol
  (node->signal [n source-node->signal])
  (sources [n]))

  CompiledGraphProtocol
  (spawn* [_ world-overrides]
    (let [spawned-world (spawn-world default-world world-overrides)
          event-mult (->> input-nodes
                          (sequence (comp (map event-topic)
                                          (map spawned-world)
                                          (filter identity)))
                          async/merge
                          async/mult)
          signal-map (build-signal-map sorted-nodes)
          output-channel (wire-up input-nodes output-node spawned-world signal-map)]
      (doseq [n input-nodes]
        (connect-events (get signal-map n) event-mult))
      (->RunningGraph spawned-world output-channel))))

(defn remove-duplicate-inputs
