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

Add colors collections persistence.

This commit is contained in:
Andrey Antukh 2015-12-24 19:32:10 +02:00
parent f37986d5c1
commit d1fc7959a1
2 changed files with 27 additions and 7 deletions

View file

@ -13,6 +13,7 @@
"Initialize the storage subsystem."
[]
(let [lens (l/select-keys [:pages-by-id
:colors-by-id
:projects-by-id])
stream (->> (l/focus-atom lens st/state)
(rx/from-atom)

View file

@ -7,6 +7,30 @@
[uxbox.data.projects :as dp]
[bouncer.validators :as v]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn assoc-color
"A reduce function for assoc the project
to the state map."
[state color-coll]
(let [uuid (:id color-coll)]
(update-in state [:colors-by-id] assoc uuid color-coll)))
(defn persist-state
[state]
(let [pages (into #{} (vals (:pages-by-id state)))
projects (into #{} (vals (:projects-by-id state)))
color-colls (into #{} (vals (:colors-by-id state)))]
(assoc! local-storage :data {:pages pages
:projects projects
:color-collections color-colls})))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn load-data
"Load data from local storage."
[]
@ -16,12 +40,7 @@
(if-let [data (get local-storage :data nil)]
(as-> state $
(reduce dp/assoc-project $ (:projects data))
(reduce dp/assoc-page $ (:pages data)))
(reduce dp/assoc-page $ (:pages data))
(reduce assoc-color $ (:color-collections data)))
state))))
(defn persist-state
[state]
(let [pages (into #{} (vals (:pages-by-id state)))
projects (into #{} (vals (:projects-by-id state)))]
(assoc! local-storage :data {:pages pages
:projects projects})))