From 5a66361746a6ee4c29a5a5eee72d22f9820d8575 Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Sun, 14 Sep 2014 21:30:19 +0300 Subject: [PATCH] Rename sync -> diff --- src/clj/grub/state.clj | 10 +++---- src/cljs/grub/state.cljs | 6 ++-- src/cljs/grub/websocket.cljs | 4 +-- src/cljx/grub/common_state.cljx | 4 +-- src/cljx/grub/{sync.cljx => diff.cljx} | 2 +- .../grub/test/unit/{sync.clj => diff.clj} | 28 +++++++++---------- 6 files changed, 26 insertions(+), 28 deletions(-) rename src/cljx/grub/{sync.cljx => diff.cljx} (98%) rename src/test/grub/test/unit/{sync.clj => diff.clj} (88%) diff --git a/src/clj/grub/state.clj b/src/clj/grub/state.clj index ed50836..3b19142 100644 --- a/src/clj/grub/state.clj +++ b/src/clj/grub/state.clj @@ -1,5 +1,5 @@ (ns grub.state - (:require [grub.sync :as sync] + (:require [grub.diff :as diff] [grub.util :as util] [grub.common-state :as cs] [clojure.core.async :as a :refer [! chan go]] @@ -42,10 +42,10 @@ (if (= (hasch/uuid @client-state) shadow-hash) ;; We have what they thought we had ;; Apply changes normally - (let [new-shadow (swap! client-state sync/patch-state diff)] + (let [new-shadow (swap! client-state diff/patch-state diff)] (log "Hash matched state, apply changes") (if (= (hasch/uuid new-shadow) hash) - (let [new-state (swap! state sync/patch-state diff)] + (let [new-state (swap! state diff/patch-state diff)] (>! @to-db diff)) (do (log "Applying diff failed --> full sync") (let [sync-state @state] @@ -60,9 +60,9 @@ ;; reset client state to this and continue as normal (do (reset! client-state history-state) - (let [new-shadow (swap! client-state sync/patch-state diff)] + (let [new-shadow (swap! client-state diff/patch-state diff)] (if (= (hasch/uuid new-shadow) hash) - (let [new-state (swap! state sync/patch-state diff)] + (let [new-state (swap! state diff/patch-state diff)] (>! @to-db diff)) (do (log "Applying diff failed --> full sync") (let [sync-state @state] diff --git a/src/cljs/grub/state.cljs b/src/cljs/grub/state.cljs index 34f5c6c..3c451c5 100644 --- a/src/cljs/grub/state.cljs +++ b/src/cljs/grub/state.cljs @@ -1,5 +1,5 @@ (ns grub.state - (:require [grub.sync :as sync] + (:require [grub.diff :as diff] [grub.common-state :as cs] [cljs.core.async :as a :refer [! chan]] [hasch.core :as hasch]) @@ -33,9 +33,9 @@ (if-let [acked-server-state (get-server-state shadow-hash)] (do (reset! server-state acked-server-state) (reset! unacked-states {}) - (let [new-server (swap! server-state #(sync/patch-state % diff))] + (let [new-server (swap! server-state #(diff/patch-state % diff))] (if (= (hasch/uuid new-server) hash) - (swap! state sync/patch-state diff) + (swap! state diff/patch-state diff) (do (log "State update failure --> complete sync") (a/put! from cs/complete-sync-request))))) (do (log "Could not find server state locally --> complete sync") diff --git a/src/cljs/grub/websocket.cljs b/src/cljs/grub/websocket.cljs index f64bd8a..1fb0968 100644 --- a/src/cljs/grub/websocket.cljs +++ b/src/cljs/grub/websocket.cljs @@ -1,7 +1,5 @@ (ns grub.websocket - (:require [grub.state :as state] - [grub.sync :as sync] - [cljs.core.async :as a :refer [! chan]] + (:require [cljs.core.async :as a :refer [! chan]] [cljs.reader] goog.net.WebSocket goog.events.EventHandler diff --git a/src/cljx/grub/common_state.cljx b/src/cljx/grub/common_state.cljx index 0e8d8d5..aaa2537 100644 --- a/src/cljx/grub/common_state.cljx +++ b/src/cljx/grub/common_state.cljx @@ -1,5 +1,5 @@ (ns grub.common-state - (:require [grub.sync :as sync] + (:require [grub.diff :as diff] [hasch.core :as hasch])) (def empty-state {:grubs {} :recipes {}}) @@ -16,7 +16,7 @@ :shadow-hash shadow-hash}) (defn diff-states [shadow state] - (let [diff (sync/diff-states shadow state) + (let [diff (diff/diff-states shadow state) hash (hasch/uuid state) shadow-hash (hasch/uuid shadow) msg (diff-msg diff hash shadow-hash)] diff --git a/src/cljx/grub/sync.cljx b/src/cljx/grub/diff.cljx similarity index 98% rename from src/cljx/grub/sync.cljx rename to src/cljx/grub/diff.cljx index f18f26c..879d367 100644 --- a/src/cljx/grub/sync.cljx +++ b/src/cljx/grub/diff.cljx @@ -1,4 +1,4 @@ -(ns grub.sync +(ns grub.diff (:require [clojure.data :as data] [clojure.set :as set])) diff --git a/src/test/grub/test/unit/sync.clj b/src/test/grub/test/unit/diff.clj similarity index 88% rename from src/test/grub/test/unit/sync.clj rename to src/test/grub/test/unit/diff.clj index 581c2f0..e71e755 100644 --- a/src/test/grub/test/unit/sync.clj +++ b/src/test/grub/test/unit/diff.clj @@ -1,5 +1,5 @@ -(ns grub.test.unit.sync - (:require [grub.sync :as sync] +(ns grub.test.unit.diff + (:require [grub.diff :as diff] [clojure.test :refer :all])) @@ -9,39 +9,39 @@ (deftest diff-empty-states (let [empty-state {:grubs {} :recipes {}}] (is (= empty-diff - (sync/diff-states empty-state empty-state))))) + (diff/diff-states empty-state empty-state))))) (deftest diff-equal-states (is (= empty-diff - (sync/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} + (diff/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} {:grubs {"id" {:text "asdf" :completed false}} :recipes {}})))) (deftest diff-added-grub (is (= {:grubs {:deleted #{} :updated {"id" {:completed false, :text "asdf"}}} :recipes {:deleted #{} :updated nil}} - (sync/diff-states {:grubs {} :recipes {}} + (diff/diff-states {:grubs {} :recipes {}} {:grubs {"id" {:text "asdf" :completed false}} :recipes {}})))) (deftest diff-deleted-grub (is (= {:grubs {:deleted #{"id"} :updated nil} :recipes {:deleted #{} :updated nil}} - (sync/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} + (diff/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} {:grubs {} :recipes {}})))) (deftest diff-edited-grub (is (= {:grubs {:deleted #{} :updated {"id" {:text "asdf2"}}} :recipes {:deleted #{} :updated nil}} - (sync/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} + (diff/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} {:grubs {"id" {:text "asdf2" :completed false}} :recipes {}})))) (deftest diff-completed-grub (is (= {:grubs {:deleted #{} :updated {"id" {:completed true}}} :recipes {:deleted #{} :updated nil}} - (sync/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} + (diff/diff-states {:grubs {"id" {:text "asdf" :completed false}} :recipes {}} {:grubs {"id" {:text "asdf" :completed true}} :recipes {}})))) (deftest diff-added-recipe @@ -49,7 +49,7 @@ :updated nil} :recipes {:deleted #{} :updated {"id" {:name "Blue Cheese Soup" :grubs "Some grubs"}}}} - (sync/diff-states {:grubs {} :recipes {}} + (diff/diff-states {:grubs {} :recipes {}} {:grubs {} :recipes {"id" {:name "Blue Cheese Soup" :grubs "Some grubs"}}})))) @@ -57,7 +57,7 @@ (is (= {:grubs {:deleted #{} :updated nil} :recipes {:deleted #{} :updated {"id" {:name "Bleu Cheese Soup" }}}} - (sync/diff-states {:grubs {} :recipes {"id" {:name "Blue Cheese Soup" + (diff/diff-states {:grubs {} :recipes {"id" {:name "Blue Cheese Soup" :grubs "Some grubs"}}} {:grubs {} :recipes {"id" {:name "Bleu Cheese Soup" :grubs "Some grubs"}}})))) @@ -65,7 +65,7 @@ (deftest diff-deleted-recipe (is (= {:grubs {:deleted #{} :updated nil} :recipes {:deleted #{"id"} :updated nil}} - (sync/diff-states {:grubs {} :recipes {"id" {:name "Blue Cheese Soup" + (diff/diff-states {:grubs {} :recipes {"id" {:name "Blue Cheese Soup" :grubs "Some grubs"}}} {:grubs {} :recipes {}})))) @@ -125,9 +125,9 @@ {:completed false :text "Toothpaste"}}}}) (deftest diff-many-changes - (is (= expected-diff (sync/diff-states before-state after-state)))) + (is (= expected-diff (diff/diff-states before-state after-state)))) (deftest patch-returns-original-state (is - (let [diff (sync/diff-states before-state after-state)] - (= after-state (sync/patch-state before-state diff))))) + (let [diff (diff/diff-states before-state after-state)] + (= after-state (diff/patch-state before-state diff)))))