From 8f5814e07ecd137f9f1d47fad7348cbce7e8e970 Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Mon, 13 Oct 2014 20:48:13 +0300 Subject: [PATCH] Simplify state functions --- src/cljx/grub/state.cljx | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cljx/grub/state.cljx b/src/cljx/grub/state.cljx index 2cc57f7..dfa919f 100644 --- a/src/cljx/grub/state.cljx +++ b/src/cljx/grub/state.cljx @@ -51,25 +51,18 @@ {:new-states (sync/add-history-state states state) :out-event (when-not (sync/empty-diff? diff) (message/diff-msg diff hash))})) -(defn make-agent - ([client? remote states*] (make-agent client? remote states* sync/empty-state)) - ([client? remote states* initial-shadow] - (go (loop [shadow initial-shadow] - (when-let [msg (remote out-event)) - (recur (if new-shadow new-shadow shadow)))))))) +(defn make-agent [client? remote states* initial-shadow] + (go (loop [shadow initial-shadow] + (when-let [msg (remote out-event)) + (recur (if new-shadow new-shadow shadow))))))) -(defn make-server-agent - ([remote states] (make-agent false remote states)) - ([remote states initial-shadow] (make-agent false remote states initial-shadow))) - -(defn make-client-agent - ([remote states] (make-agent true remote states)) - ([remote states initial-shadow] (make-agent true remote states initial-shadow))) +(def make-server-agent (partial make-agent false)) +(def make-client-agent (partial make-agent true)) #+clj (defn sync-new-client! [>client client states))) + (make-server-agent client-events >client states sync/empty-state))) #+clj (defn init-server [to-db initial-state] @@ -104,6 +97,6 @@ (let [new-state (sync/get-current-state new-states)] (a/put! >view new-state)))) (a/pipe remote states) + (make-client-agent (a/merge [local-events remote states sync/empty-state) (a/put! >remote message/full-sync-request) states))