Improve page helpers functions naming.

This commit is contained in:
Andrey Antukh 2016-11-10 18:30:10 +01:00
parent 870c2d9fb1
commit bf03a87c17
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 29 additions and 32 deletions

View file

@ -120,7 +120,7 @@
:history true :history true
:data (:data item))] :data (:data item))]
(-> state (-> state
(udp/unpack-page page) (udp/assoc-page page)
(assoc-in [:workspace :history :selected] version))))) (assoc-in [:workspace :history :selected] version)))))
(defn select-page-history (defn select-page-history
@ -149,8 +149,8 @@
(defrecord DeselectPageHistory [id] (defrecord DeselectPageHistory [id]
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(let [packed (get-in state [:pagedata-by-id id])] (let [packed (get-in state [:packed-pages id])]
(-> (udp/unpack-page state packed) (-> (udp/assoc-page state packed)
(assoc-in [:workspace :history :deselecting] true) (assoc-in [:workspace :history :deselecting] true)
(assoc-in [:workspace :history :selected] nil)))) (assoc-in [:workspace :history :selected] nil))))

View file

@ -19,21 +19,14 @@
[uxbox.util.datetime :as dt] [uxbox.util.datetime :as dt]
[uxbox.util.data :refer (without-keys replace-by-id)])) [uxbox.util.data :refer (without-keys replace-by-id)]))
;; --- Protocols
(defprotocol IPageUpdate (defprotocol IPageUpdate
"A marker protocol for mark events that alters the "A marker protocol for mark events that alters the
page and is subject to perform a backend synchronization.") page and is subject to perform a backend synchronization.")
;; --- Page Pack/Unpack ;; --- Helpers
(defn dissoc-page-shapes
[state id]
(let [shapes (get state :shapes)]
(assoc state :shapes (reduce-kv (fn [acc k v]
(if (= (:page v) id)
(dissoc acc k)
acc))
shapes
shapes))))
(defn pack-page (defn pack-page
"Return a packed version of page object ready "Return a packed version of page object ready
@ -47,7 +40,7 @@
(assoc-in [:data :shapes-map] shapes) (assoc-in [:data :shapes-map] shapes)
(dissoc :shapes)))) (dissoc :shapes))))
(defn unpack-page (defn assoc-page
"Unpacks packed page object and assocs it to the "Unpacks packed page object and assocs it to the
provided state." provided state."
[state {:keys [id data] :as page}] [state {:keys [id data] :as page}]
@ -63,18 +56,24 @@
(defn purge-page (defn purge-page
"Remove page and all related stuff from the state." "Remove page and all related stuff from the state."
[state id] [state id]
(let [shapes (get state :shapes)]
(-> state (-> state
(update :pages dissoc id) (update :pages dissoc id)
(update :pagedata-by-id dissoc id) (update :packed-pages dissoc id)
(dissoc-page-shapes id))) (assoc :shapes (reduce-kv (fn [acc k v]
(if (= (:page v) id)
(dissoc acc k)
acc))
shapes
shapes)))))
(defn assoc-page (defn assoc-packed-page
[state {:keys [id] :as page}] [state {:keys [id] :as page}]
(assoc-in state [:pagedata-by-id id] page)) (assoc-in state [:packed-pages id] page))
(defn dissoc-page (defn dissoc-packed-page
[state id] [state id]
(update state :pagedata-by-id dissoc id)) (update state :packed-pages dissoc id))
;; --- Pages Fetched ;; --- Pages Fetched
@ -82,8 +81,8 @@
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(as-> state $ (as-> state $
(reduce unpack-page $ pages) (reduce assoc-page $ pages)
(reduce assoc-page $ pages)))) (reduce assoc-packed-page $ pages))))
(defn pages-fetched? (defn pages-fetched?
[v] [v]
@ -108,8 +107,8 @@
(-apply-watch [this state s] (-apply-watch [this state s]
(letfn [(on-created [{page :payload}] (letfn [(on-created [{page :payload}]
(rx/of (rx/of
#(unpack-page % page) #(assoc-page % page)
#(assoc-page % page)))] #(assoc-packed-page % page)))]
(let [params {:name name (let [params {:name name
:project project :project project
:data {} :data {}
@ -217,9 +216,7 @@
:project [sc/required] :project [sc/required]
:version [sc/required] :version [sc/required]
:name [sc/required sc/string] :name [sc/required sc/string]
:width [sc/required sc/integer] :metadata [sc/required]})
:height [sc/required sc/integer]
:layout [sc/required sc/string]})
(defn update-page-metadata (defn update-page-metadata
[data] [data]

View file

@ -102,7 +102,7 @@
;; (pp/pprint packed) ;; (pp/pprint packed)
(-> state (-> state
(udp/unpack-page packed) (udp/assoc-page packed)
(assoc-in [:undo page-id :selected] pointer))))))) (assoc-in [:undo page-id :selected] pointer)))))))
(defn undo (defn undo
@ -135,7 +135,7 @@
;; (pp/pprint packed) ;; (pp/pprint packed)
(-> state (-> state
(udp/unpack-page packed) (udp/assoc-page packed)
(assoc-in [:undo page-id :selected] pointer))))))) (assoc-in [:undo page-id :selected] pointer)))))))
(defn redo (defn redo