From e6b3c103960a5a646e24d59c2164f296dee5ac5f Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Thu, 25 Sep 2014 23:16:57 +0300 Subject: [PATCH] Move state handling to shared code --- src/{clj/grub/state.clj => cljx/grub/state.cljx} | 9 ++++----- src/test/grub/test/unit/state.clj | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) rename src/{clj/grub/state.clj => cljx/grub/state.cljx} (89%) diff --git a/src/clj/grub/state.clj b/src/cljx/grub/state.cljx similarity index 89% rename from src/clj/grub/state.clj rename to src/cljx/grub/state.cljx index 6fb1348..9a980b5 100644 --- a/src/clj/grub/state.clj +++ b/src/cljx/grub/state.cljx @@ -7,8 +7,8 @@ ;; Server state (def states (atom [])) -(defn make-server-agent - ([in out states] (make-server-agent in out states sync/empty-state)) +(defn make-agent + ([in out states] (make-agent in out states sync/empty-state)) ([in out states initial-client-state] (a/go-loop [client-state initial-client-state] (when-let [msg (! out (message/diff-msg diff hash))) - (do (println "Unknown message:" msg) - (recur client-state))))))) + (recur client-state)))))) ;; TODO: Remove watch, close up channels properly (defn sync-new-client! [>client client states))) + (make-agent client-events >client states))) (defn init [to-db grubs recipes] (reset! states (sync/initial-state grubs recipes)) diff --git a/src/test/grub/test/unit/state.clj b/src/test/grub/test/unit/state.clj index 186229f..c124d14 100644 --- a/src/test/grub/test/unit/state.clj +++ b/src/test/grub/test/unit/state.clj @@ -21,7 +21,7 @@ :hash (:hash (first states))} in (chan 1) out (chan 1)] - (state/make-server-agent in out states*) + (state/make-agent in out states*) (>!! in msg) (let [diff-response (!! in msg) (let [diff-response (!! in msg) (let [diff-response (!! in msg) (let [diff-response (!! in msg) (let [diff-response (