mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
✨ Simplify fdata feature helpers
This commit is contained in:
parent
757291644b
commit
41794c5f5e
1 changed files with 24 additions and 33 deletions
|
@ -22,18 +22,16 @@
|
||||||
|
|
||||||
(defn enable-objects-map
|
(defn enable-objects-map
|
||||||
[file]
|
[file]
|
||||||
(let [update-container
|
(let [update-page
|
||||||
(fn [container]
|
(fn [page]
|
||||||
(if (and (pmap/pointer-map? container)
|
(if (and (pmap/pointer-map? page)
|
||||||
(not (pmap/loaded? container)))
|
(not (pmap/loaded? page)))
|
||||||
container
|
page
|
||||||
(d/update-when container :objects omap/wrap)))
|
(update page :objects omap/wrap)))
|
||||||
|
|
||||||
update-data
|
update-data
|
||||||
(fn [fdata]
|
(fn [fdata]
|
||||||
(-> fdata
|
(update fdata :pages-index d/update-vals update-page))]
|
||||||
(update :pages-index d/update-vals update-container)
|
|
||||||
(d/update-when :components d/update-vals update-container)))]
|
|
||||||
|
|
||||||
(-> file
|
(-> file
|
||||||
(update :data update-data)
|
(update :data update-data)
|
||||||
|
@ -43,19 +41,15 @@
|
||||||
"Apply a function to all objects-map on the file. Usualy used for convert
|
"Apply a function to all objects-map on the file. Usualy used for convert
|
||||||
the objects-map instances to plain maps"
|
the objects-map instances to plain maps"
|
||||||
[fdata update-fn]
|
[fdata update-fn]
|
||||||
(let [update-container
|
(if (contains? fdata :pages-index)
|
||||||
(fn [container]
|
(update fdata :pages-index d/update-vals
|
||||||
(d/update-when container :objects
|
(fn [page]
|
||||||
(fn [objects]
|
(update page :objects
|
||||||
(if (omap/objects-map? objects)
|
(fn [objects]
|
||||||
(update-fn objects)
|
(if (omap/objects-map? objects)
|
||||||
objects))))]
|
(update-fn objects)
|
||||||
(cond-> fdata
|
objects)))))
|
||||||
(contains? fdata :pages-index)
|
fdata))
|
||||||
(update :pages-index update-vals update-container)
|
|
||||||
|
|
||||||
(contains? fdata :components)
|
|
||||||
(update :components update-vals update-container))))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; POINTER-MAP
|
;; POINTER-MAP
|
||||||
|
@ -95,15 +89,13 @@
|
||||||
"Apply a function to all pointers on the file. Usuly used for
|
"Apply a function to all pointers on the file. Usuly used for
|
||||||
dereference the pointer to a plain value before some processing."
|
dereference the pointer to a plain value before some processing."
|
||||||
[fdata update-fn]
|
[fdata update-fn]
|
||||||
(cond-> fdata
|
(let [update-fn' (fn [val]
|
||||||
(contains? fdata :pages-index)
|
(if (pmap/pointer-map? val)
|
||||||
(update :pages-index process-pointers update-fn)
|
(update-fn val)
|
||||||
|
val))]
|
||||||
:always
|
(-> fdata
|
||||||
(update-vals (fn [val]
|
(d/update-vals update-fn')
|
||||||
(if (pmap/pointer-map? val)
|
(update :pages-index d/update-vals update-fn'))))
|
||||||
(update-fn val)
|
|
||||||
val)))))
|
|
||||||
|
|
||||||
(defn get-used-pointer-ids
|
(defn get-used-pointer-ids
|
||||||
"Given a file, return all pointer ids used in the data."
|
"Given a file, return all pointer ids used in the data."
|
||||||
|
@ -119,7 +111,6 @@
|
||||||
(-> file
|
(-> file
|
||||||
(update :data (fn [fdata]
|
(update :data (fn [fdata]
|
||||||
(-> fdata
|
(-> fdata
|
||||||
(update :pages-index update-vals pmap/wrap)
|
(update :pages-index d/update-vals pmap/wrap)
|
||||||
(d/update-when :components pmap/wrap))))
|
(d/update-when :components pmap/wrap))))
|
||||||
|
|
||||||
(update :features conj "fdata/pointer-map")))
|
(update :features conj "fdata/pointer-map")))
|
||||||
|
|
Loading…
Add table
Reference in a new issue