0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-02 18:11:20 -05:00

Add more safer shapes packing mechanism.

This commit is contained in:
Andrey Antukh 2017-01-31 00:07:53 +01:00
parent 12b9868f45
commit aba35dee61
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 26 additions and 6 deletions

View file

@ -76,15 +76,36 @@
;; --- Helpers
;; TODO: make sure remove all :tmp-* related attrs from shape
(defn pack-page-shapes
"Create a hash-map of shapes indexed by their id that belongs
to the provided page."
[state page]
(let [lookup-shape-xf (map #(get-in state [:shapes %]))]
(reduce (fn reducer [acc {:keys [id type items] :as shape}]
(let [shape (assoc shape :page (:id page))]
(cond
(= type :group)
(reduce reducer
(assoc acc id shape)
(sequence lookup-shape-xf items))
(uuid? id)
(assoc acc id shape)
:else acc)))
{}
(sequence lookup-shape-xf (:shapes page)))))
(defn pack-page
"Return a packed version of page object ready
for send to remore storage service."
[state id]
(let [page (get-in state [:pages id])
xf (filter #(= (:page (second %)) id))
shapes (into {} xf (:shapes state))]
shapes (pack-page-shapes state page)]
(-> page
(assoc-in [:data :shapes] (into [] (:shapes page)))
(assoc-in [:data :shapes] (vec (:shapes page)))
(assoc-in [:data :shapes-map] shapes)
(dissoc :shapes))))
@ -303,7 +324,6 @@
(defn update-page
[id data]
(println "update-page" data)
{:pre [(uuid? id) (us/valid? ::page-entity data)]}
(UpdatePage. id data))

View file

@ -48,7 +48,7 @@
(shape-wrapper shape)))
(mx/defc page-svg
[{:keys [metadata] :as page}]
[{:keys [id metadata] :as page}]
(let [{:keys [width height]} metadata]
[:svg {:width width
:height height

View file

@ -42,7 +42,7 @@
[]
(letfn [(on-move [shape delta]
(st/emit! (uds/apply-temporal-displacement shape delta)))
(on-stop [{:keys [id] :as shape}]
(on-stop [shape]
(st/emit! (uds/apply-displacement shape)))
(on-start [shape]
(let [stoper (->> streams/events