             [cbfg.world.lane]
             [cbfg.world.base :refer [world-cmd-loop]]))
 
-;; TODO: How to assign locations to world entities before rendering?
+(def prog-base (atom {})) ; { :world => world-actx
+                          ;   :net-listen-ch => ch
+                          ;   :net-connect-ch => ch
+                          ;   :res-ch => ch }
 
 (def prog-history
   (atom {:snapshots {0 {}
                      10 {:a 1 :b 2 :c 3 :d 4}
                      20 {:a 11 :b 22 :c 33 :d 44}}
-         :prog-world {} ; { :world => world-actx
-                        ;   :net-listen-ch => ch
-                        ;   :net-connect-ch => ch
-                        ;   :servers => { server-addr => ports }
-                        ;   :clients => { client-addr => client-info }
-                        ;   :res-ch => ch }
-         :prog-events [[0 :snapshot]
-                       [1 :event [:a 1]]
-                       [2 :event [:b 2]]
-                       [3 :event [:c 3]]
-                       [4 :event [:d 4]]]}))
+         :prog-peers {:servers {}  ; { server-addr => ports }
+                      :clients {}} ; { client-addr => client-info }
+         :prog-events []}))
 
 (def run-world       (atom {:a 10}))
 (def run-world-hover (atom nil))

; --------------------------------------------

(defn kv-server [server-addr & ports]
  (let [prog-world (:prog-world @prog-history)
        world (:world prog-world)
        done (atom false)]
    (act server-init world
         (doseq [port ports]
           (when-let [listen-result-ch (achan server-init)]
             (aput server-init (:net-listen-ch prog-world)
                   [server-addr port listen-result-ch])
             (when-let [[accept-ch close-accept-ch] (atake server-init listen-result-ch)]
               (cbfg.world.net/server-accept-loop world accept-ch close-accept-ch)
               (swap! prog-history
                      #(let [ph (update-in % [:prog-world :servers server-addr]
                                           conj port)]
                         (update-in ph [:prog-events] conj
                                    [(count (:prog-events ph))
                                     :event
                                     (:prog-world ph)]))))))
         (reset! done true))
    (wait-done done)))

(defn kv-client [client-addr server-addr server-port]
  (let [prog-world (:prog-world @prog-history)
        world (:world prog-world)
        done (atom false)]
    (act client-init world
         (let [req-ch (cbfg.world.net/client-loop world (:net-connect-ch prog-world)
                                                  server-addr server-port
                                                  client-addr (:res-ch prog-world))]
           (swap! prog-history
                  #(let [ph (assoc-in % [:prog-world :clients client-addr]
                                      {:client-addr client-addr
                                       :server-addr server-addr
                                       :server-port server-port

           (fn [[last-snapshot-ts res] [ts kind args]]
             (if (= kind :snapshot)
               [ts (conj res

                         (dom/li #js {:className "snapshot"
                                      :onMouseEnter #(on-event-focus ts nil)
                                      :onMouseLeave #(on-event-blur ts nil)}
