From 931042018e7971ed49b6ae0dea6178a2bc37b051 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 24 May 2016 21:40:06 +0300 Subject: [PATCH] Move image collections state transformations functions into data ns. --- src/uxbox/data/images.cljs | 12 +++++++----- src/uxbox/state/images.cljs | 27 --------------------------- 2 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 src/uxbox/state/images.cljs diff --git a/src/uxbox/data/images.cljs b/src/uxbox/data/images.cljs index eb99afdb4..b3321d010 100644 --- a/src/uxbox/data/images.cljs +++ b/src/uxbox/data/images.cljs @@ -11,7 +11,6 @@ [uuid.core :as uuid] [uxbox.rstore :as rs] [uxbox.state :as st] - [uxbox.state.images :as sti] [uxbox.repo :as rp])) ;; --- Initialize @@ -46,7 +45,10 @@ (defrecord CollectionsFetched [items] rs/UpdateEvent (-apply-update [_ state] - (reduce sti/assoc-collection state items))) + (reduce (fn [acc {:keys [id] :as item}] + (assoc-in acc [:images-by-id id] item)) + state + items))) (defn collections-fetched [items] @@ -71,7 +73,7 @@ rs/UpdateEvent (-apply-update [_ state] (-> state - (sti/assoc-collection item) + (assoc-in [:images-by-id (:id item)] item) (assoc-in [:dashboard :collection-id] (:id item)) (assoc-in [:dashboard :collection-type] :own)))) @@ -143,7 +145,7 @@ (defrecord DeleteCollection [id] rs/UpdateEvent (-apply-update [_ state] - (sti/dissoc-collection state id)) + (update state :images-by-id dissoc id)) rs/WatchEvent (-apply-watch [_ state s] @@ -218,7 +220,7 @@ (defrecord DeleteImage [coll-id image] rs/UpdateEvent (-apply-update [_ state] - (sti/dissoc-image state coll-id image)) + (update-in state [:images-by-id coll-id :images] disj image)) rs/WatchEvent (-apply-watch [_ state s] diff --git a/src/uxbox/state/images.cljs b/src/uxbox/state/images.cljs deleted file mode 100644 index 9ebbdd2c9..000000000 --- a/src/uxbox/state/images.cljs +++ /dev/null @@ -1,27 +0,0 @@ -(ns uxbox.state.images) - -(defn assoc-collection - "A reduce function for assoc the image collection - to the state map." - [state coll] - (let [id (:id coll)] - (assoc-in state [:images-by-id id] coll))) - -(defn dissoc-collection - "A reduce function for dissoc the image collection - to the state map." - [state id] - (update state :images-by-id dissoc id)) - -(defn select-first-collection - "A reduce function for select the first image collection - to the state map." - [state] - (let [colls (sort-by :id (vals (:images-by-id state)))] - (assoc-in state [:dashboard :collection-id] (:id (first colls))))) - -(defn dissoc-image - "A reduce function for dissoc the image collection - to the state map." - [state coll-id image] - (update-in state [:images-by-id coll-id :images] disj image))