From 3e4678a08599cbd66fe7dc42672e6bdb91d4fd00 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 19 Mar 2016 12:51:36 +0200 Subject: [PATCH] Simplify project manipulation state functions. --- src/uxbox/state/project.cljs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/uxbox/state/project.cljs b/src/uxbox/state/project.cljs index 0922e9620..ee9c750e8 100644 --- a/src/uxbox/state/project.cljs +++ b/src/uxbox/state/project.cljs @@ -11,9 +11,8 @@ (defn dissoc-project "A reduce function for dissoc the project from the state map." - [state proj] - (let [uuid (:id proj)] - (update-in state [:projects-by-id] dissoc uuid))) + [state id] + (update-in state [:projects-by-id] dissoc id)) (defn assoc-page "A reduce function for assoc the page @@ -22,6 +21,23 @@ (let [uuid (:id page)] (update-in state [:pages-by-id] assoc uuid page))) +(defn dissoc-page-shapes + [state id] + (let [shapes (get-in state [:shapes-by-id])] + (assoc state :shapes-by-id (reduce-kv (fn [acc k v] + (if (= (:page v) id) + (dissoc acc k) + acc)) + shapes + shapes)))) + +(defn dissoc-page + "Remove page and all related stuff from the state." + [state id] + (-> state + (update :pages-by-id dissoc id) + (dissoc-page-shapes id))) + (defn project-pages "Get a ordered list of pages that belongs to a specified project."