0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 15:09:10 -05:00

Move image collections state transformations functions into data ns.

This commit is contained in:
Andrey Antukh 2016-05-24 21:40:06 +03:00
parent fa98c544cc
commit 931042018e
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 7 additions and 32 deletions

View file

@ -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]

View file

@ -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))