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

💄 Add syntax improvements on libraries helpers.

This commit is contained in:
Andrey Antukh 2021-12-03 16:35:10 +01:00 committed by Andrés Moya
parent beff3fe843
commit 9925716134

View file

@ -53,9 +53,11 @@
(declare make-change) (declare make-change)
(defn concat-changes (defn concat-changes
[[rchanges1 uchanges1] [rchanges2 uchanges2]] [& rest]
(letfn [(concat-changes' [[rchanges1 uchanges1] [rchanges2 uchanges2]]
[(d/concat-vec rchanges1 rchanges2) [(d/concat-vec rchanges1 rchanges2)
(d/concat-vec uchanges1 uchanges2)]) (d/concat-vec uchanges1 uchanges2)])]
(transduce (remove nil?) concat-changes' empty-changes rest)))
(defn get-local-file (defn get-local-file
[state] [state]
@ -669,20 +671,16 @@
root-main root-main
container container
omit-touched?) omit-touched?)
(concat-changes (when reset?
(if reset?
(change-touched shape-inst (change-touched shape-inst
shape-main shape-main
container container
{:reset-touched? true}) {:reset-touched? true}))
empty-changes) (when clear-remote-synced?
(concat-changes (change-remote-synced shape-inst container nil))
(if clear-remote-synced?
(change-remote-synced shape-inst container nil) (when set-remote-synced?
empty-changes) (change-remote-synced shape-inst container true)))
(if set-remote-synced?
(change-remote-synced shape-inst container true)
empty-changes))))
children-inst (mapv #(cp/get-shape container %) children-inst (mapv #(cp/get-shape container %)
(:shapes shape-inst)) (:shapes shape-inst))
@ -792,23 +790,19 @@
root-inst root-inst
component-container component-container
omit-touched?) omit-touched?)
(concat-changes
(change-touched shape-inst (change-touched shape-inst
shape-main shape-main
container container
{:reset-touched? true}) {:reset-touched? true})
(concat-changes
(change-touched shape-main (change-touched shape-main
shape-inst shape-inst
component-container component-container
{:copy-touched? true}) {:copy-touched? true})
(concat-changes (when clear-remote-synced?
(if clear-remote-synced? (change-remote-synced shape-inst container nil))
(change-remote-synced shape-inst container nil)
empty-changes) (when set-remote-synced?
(if set-remote-synced? (change-remote-synced shape-inst container true)))
(change-remote-synced shape-inst container true)
empty-changes)))))
children-inst (mapv #(cp/get-shape container %) children-inst (mapv #(cp/get-shape container %)
(:shapes shape-inst)) (:shapes shape-inst))
@ -876,61 +870,50 @@
[children-inst children-main only-inst-cb only-main-cb both-cb moved-cb inverse?] [children-inst children-main only-inst-cb only-main-cb both-cb moved-cb inverse?]
(loop [children-inst (seq (or children-inst [])) (loop [children-inst (seq (or children-inst []))
children-main (seq (or children-main [])) children-main (seq (or children-main []))
[rchanges uchanges] [[] []]] changes [[] []]]
(let [child-inst (first children-inst) (let [child-inst (first children-inst)
child-main (first children-main)] child-main (first children-main)]
(cond (cond
(and (nil? child-inst) (nil? child-main)) (and (nil? child-inst) (nil? child-main))
[rchanges uchanges] changes
(nil? child-inst) (nil? child-inst)
(reduce (fn [changes child] (transduce (map only-main-cb) concat-changes changes children-main)
(concat-changes changes (only-main-cb child)))
[rchanges uchanges]
children-main)
(nil? child-main) (nil? child-main)
(reduce (fn [changes child] (transduce (map only-inst-cb) concat-changes changes children-inst)
(concat-changes changes (only-inst-cb child)))
[rchanges uchanges]
children-inst)
:else :else
(if (cp/is-main-of child-main child-inst) (if (cp/is-main-of child-main child-inst)
(recur (next children-inst) (recur (next children-inst)
(next children-main) (next children-main)
(concat-changes [rchanges uchanges] (concat-changes changes (both-cb child-inst child-main)))
(both-cb child-inst child-main)))
(let [child-inst' (d/seek #(cp/is-main-of child-main %) (let [child-inst' (d/seek #(cp/is-main-of child-main %) children-inst)
children-inst) child-main' (d/seek #(cp/is-main-of % child-inst) children-main)]
child-main' (d/seek #(cp/is-main-of % child-inst)
children-main)]
(cond (cond
(nil? child-inst') (nil? child-inst')
(recur children-inst (recur children-inst
(next children-main) (next children-main)
(concat-changes [rchanges uchanges] (concat-changes changes (only-main-cb child-main)))
(only-main-cb child-main)))
(nil? child-main') (nil? child-main')
(recur (next children-inst) (recur (next children-inst)
children-main children-main
(concat-changes [rchanges uchanges] (concat-changes changes (only-inst-cb child-inst)))
(only-inst-cb child-inst)))
:else :else
(if inverse? (if inverse?
(recur (next children-inst) (recur (next children-inst)
(remove #(= (:id %) (:id child-main')) children-main) (remove #(= (:id %) (:id child-main')) children-main)
(-> [rchanges uchanges] (concat-changes changes
(concat-changes (both-cb child-inst' child-main)) (both-cb child-inst' child-main)
(concat-changes (moved-cb child-inst child-main')))) (moved-cb child-inst child-main')))
(recur (remove #(= (:id %) (:id child-inst')) children-inst) (recur (remove #(= (:id %) (:id child-inst')) children-inst)
(next children-main) (next children-main)
(-> [rchanges uchanges] (concat-changes changes
(concat-changes (both-cb child-inst child-main')) (both-cb child-inst child-main')
(concat-changes (moved-cb child-inst' child-main)))))))))))) (moved-cb child-inst' child-main)))))))))))
(defn- add-shape-to-instance (defn- add-shape-to-instance
[component-shape index component container root-instance root-main omit-touched? set-remote-synced?] [component-shape index component container root-instance root-main omit-touched? set-remote-synced?]