0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 00:01:51 -05:00

🐛 Avoid unneeded component update, that was generating loops

This commit is contained in:
Andrés Moya 2023-06-05 13:13:09 +02:00
parent bca90c54e9
commit 3e30d4776a
2 changed files with 20 additions and 4 deletions

View file

@ -675,7 +675,7 @@
any-sync? (some need-sync? operations)] any-sync? (some need-sync? operations)]
(when any-sync? (when any-sync?
(let [xform (comp (filter :main-instance?) ; Select shapes that are main component instances (let [xform (comp (filter :main-instance?) ; Select shapes that are main component instances
(map :id))] (map :component-id))]
(into #{} xform shape-and-parents)))))) (into #{} xform shape-and-parents))))))
(defmethod components-changed :mov-objects (defmethod components-changed :mov-objects
@ -684,7 +684,7 @@
(let [page (ctpl/get-page file-data page-id) (let [page (ctpl/get-page file-data page-id)
xform (comp (filter :main-instance?) xform (comp (filter :main-instance?)
(map :id)) (map :component-id))
check-shape check-shape
(fn [shape-id others] (fn [shape-id others]
@ -703,7 +703,7 @@
shape-and-parents (map (partial ctn/get-shape page) shape-and-parents (map (partial ctn/get-shape page)
(cons id (cph/get-parent-ids (:objects page) id))) (cons id (cph/get-parent-ids (:objects page) id)))
xform (comp (filter :main-instance?) xform (comp (filter :main-instance?)
(map :id))] (map :component-id))]
(into #{} xform shape-and-parents)))) (into #{} xform shape-and-parents))))
(defmethod components-changed :default (defmethod components-changed :default

View file

@ -665,6 +665,22 @@
(sync-file file-id file-id :components (:component-id shape) undo-group)) (sync-file file-id file-id :components (:component-id shape) undo-group))
(dwu/commit-undo-transaction undo-id))))))) (dwu/commit-undo-transaction undo-id)))))))
(defn launch-component-sync
"Launch a sync of the current file and of the library file of the given component."
([component-id file-id] (launch-component-sync component-id file-id nil))
([component-id file-id undo-group]
(ptk/reify ::launch-component-sync
ptk/WatchEvent
(watch [_ state _]
(let [current-file-id (:current-file-id state)
undo-id (js/Symbol)]
(rx/of
(dwu/start-undo-transaction undo-id)
(sync-file current-file-id file-id :components component-id undo-group)
(when (not= current-file-id file-id)
(sync-file file-id file-id :components component-id undo-group))
(dwu/commit-undo-transaction undo-id)))))))
(defn update-component-in-bulk (defn update-component-in-bulk
[shapes file-id] [shapes file-id]
(ptk/reify ::update-component-in-bulk (ptk/reify ::update-component-in-bulk
@ -897,7 +913,7 @@
:ids (map str components-changed) :ids (map str components-changed)
:undo-group undo-group) :undo-group undo-group)
(run! st/emit! (run! st/emit!
(map #(update-component-sync % (:id old-data) undo-group) (map #(launch-component-sync % (:id old-data) undo-group)
components-changed))))))] components-changed))))))]
(when components-v2 (when components-v2