From 52ce9ffb42f6a368d421cfc946c7e2195f6dd6e1 Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Fri, 10 Oct 2014 18:51:31 +0300 Subject: [PATCH] Use different events for full sync, full sync request --- src/cljx/grub/message.cljx | 2 +- src/cljx/grub/state.cljx | 17 +++++++++-------- src/test/grub/test/unit/state.clj | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cljx/grub/message.cljx b/src/cljx/grub/message.cljx index 09b94c1..7e75cc6 100644 --- a/src/cljx/grub/message.cljx +++ b/src/cljx/grub/message.cljx @@ -1,6 +1,6 @@ (ns grub.message) -(def full-sync-request {:type :full-sync}) +(def full-sync-request {:type :full-sync-request}) (defn full-sync [state] {:type :full-sync diff --git a/src/cljx/grub/state.cljx b/src/cljx/grub/state.cljx index 0fed206..06539d9 100644 --- a/src/cljx/grub/state.cljx +++ b/src/cljx/grub/state.cljx @@ -35,16 +35,17 @@ (let [state (sync/get-current-state states*)] (>! out (message/full-sync state)) (recur state))))) + + :full-sync-request + (let [state (sync/get-current-state @states)] + (>! out (message/full-sync state)) + (recur state)) :full-sync - (if client? - (let [state (:state msg)] - (reset! states (sync/new-state state)) - (recur state)) - (let [state (sync/get-current-state @states)] - (>! out (message/full-sync state)) ;; HERE - (recur state))) - + (let [state (:state msg)] + (reset! states (sync/new-state state)) + (recur state)) + :new-state (let [{:keys [diff hash]} (sync/diff-states (:state msg) shadow)] (when-not (sync/empty-diff? diff) diff --git a/src/test/grub/test/unit/state.clj b/src/test/grub/test/unit/state.clj index f925c4e..8a80cd1 100644 --- a/src/test/grub/test/unit/state.clj +++ b/src/test/grub/test/unit/state.clj @@ -97,7 +97,7 @@ {:grubs {"1" {:text "2 apples" :completed false} "2" {:text "3 onions" :completed false}} :recipes {}}) - msg {:type :full-sync} + msg {:type :full-sync-request} in (chan 1) out (chan 1)] (state/make-server-agent in out states)