0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

Simplify project manipulation state functions.

This commit is contained in:
Andrey Antukh 2016-03-19 12:51:36 +02:00
parent 6492faefd4
commit 3e4678a085

View file

@ -11,9 +11,8 @@
(defn dissoc-project (defn dissoc-project
"A reduce function for dissoc the project "A reduce function for dissoc the project
from the state map." from the state map."
[state proj] [state id]
(let [uuid (:id proj)] (update-in state [:projects-by-id] dissoc id))
(update-in state [:projects-by-id] dissoc uuid)))
(defn assoc-page (defn assoc-page
"A reduce function for assoc the page "A reduce function for assoc the page
@ -22,6 +21,23 @@
(let [uuid (:id page)] (let [uuid (:id page)]
(update-in state [:pages-by-id] assoc uuid 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 (defn project-pages
"Get a ordered list of pages that "Get a ordered list of pages that
belongs to a specified project." belongs to a specified project."