From a063557376330499babf8594e9328c13739b6576 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 14 Oct 2026 01:33:56 +0200 Subject: [PATCH] :recycle: Build the component sync events in one place update-component-sync and launch-component-sync both emitted the same pair of sync-file events: the current file, and the library file when it is another one. component-sync-events builds them for both, each event keeping its own undo transaction. The two-argument arity of launch-component-sync had no caller and is gone. No behavior change: the frontend suite and its golden master are unchanged. No common code changed, so the benchmark does not apply. AI-assisted-by: claude-opus-5-5 --- .../app/main/data/workspace/libraries.cljs | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index a45d99a3a9..b8ec979636 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -921,48 +921,53 @@ (update-component-thumbnail-sync @st/state component-id file-id "component"))) +(defn- component-sync-events + "The events that sync the copies of the component `component-id` of the + library `file-id`: in the current file, and in the library when it is + another file." + [state component-id file-id undo-group] + (let [current-file-id (:current-file-id state)] + [(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))])) + (defn update-component-sync + "Update the main of the copy `shape-id` from the copy (see + `update-component`), in one undo entry with the sync of its copies." ([shape-id file-id] (update-component-sync shape-id file-id nil)) ([shape-id file-id undo-group] (ptk/reify ::update-component-sync ptk/WatchEvent (watch [_ state _] - (let [current-file-id (:current-file-id state) - current-file? (= current-file-id file-id) + (let [page (dsh/lookup-page state) + shape (ctn/get-shape page shape-id) + component-id (:component-id shape) + undo-id (js/Symbol)] + (apply rx/of + (concat + [(dwu/start-undo-transaction undo-id) + (update-component shape-id undo-group) - page (dsh/lookup-page state) - shape (ctn/get-shape page shape-id) - component-id (:component-id shape) - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (update-component shape-id undo-group) - - ;; These calls are necessary for properly sync thumbnails - ;; when a main component does not live in the same page. - (update-component-thumbnail-sync state component-id file-id "frame") - (update-component-thumbnail-sync state component-id file-id "component") - - (sync-file current-file-id file-id :components component-id undo-group) - (when (not current-file?) - (sync-file file-id file-id :components component-id undo-group)) - (dwu/commit-undo-transaction undo-id))))))) + ;; These calls are necessary for properly sync thumbnails + ;; when a main component does not live in the same page. + (update-component-thumbnail-sync state component-id file-id "frame") + (update-component-thumbnail-sync state component-id file-id "component")] + (component-sync-events state component-id file-id undo-group) + [(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))))))) + "Launch a sync of the current file and of the library file of the given + component, in one undo entry." + [component-id file-id undo-group] + (ptk/reify ::launch-component-sync + ptk/WatchEvent + (watch [_ state _] + (let [undo-id (js/Symbol)] + (apply rx/of + (concat + [(dwu/start-undo-transaction undo-id)] + (component-sync-events state component-id file-id undo-group) + [(dwu/commit-undo-transaction undo-id)])))))) (defn update-component-thumbnail "Update the thumbnail of the component with the given id, in the