From b572d1a3db7c7ed8dedfdd112121a8ab649071ff Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Apr 2026 12:02:28 +0200 Subject: [PATCH] :sparkles: Changes after review --- .../src/app/main/data/workspace/shapes.cljs | 52 ++++++++++--------- .../data/workspace/tokens/application.cljs | 4 +- .../data/workspace/tokens/propagation.cljs | 14 +++-- .../app/main/data/workspace/wasm_text.cljs | 4 +- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index bbd5f47955..2901354999 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -46,33 +46,37 @@ (cond-> changes add-undo-group? (assoc :undo-group undo-group)))) -(defn update-shapes-debounce-start +(defn update-shapes-buffer-start [] - (ptk/reify ::update-shapes-debounce-start + (ptk/reify ::update-shapes-buffer-start ptk/UpdateEvent (update [_ state] - (assoc state ::update-shapes-debounce true)))) + (assoc state ::update-shapes-buffer true)))) -(defn update-shapes-debounce-stop +(defn update-shapes-buffer-stop [] - (ptk/reify ::update-shapes-debounce-stop + (ptk/reify ::update-shapes-buffer-stop ptk/UpdateEvent (update [_ state] - (assoc state ::update-shapes-debounce false)))) + (assoc state ::update-shapes-buffer false)))) -(defn update-shapes-debounce-commit +(defn update-shapes-buffer-commit [] - (ptk/reify ::update-shapes-debounce-commit + (ptk/reify ::update-shapes-buffer-commit ptk/WatchEvent (watch [_ state _] - (->> (get state ::update-shapes-debounce-changes) + (->> (get state ::update-shapes-buffer-changes) (vals) (map dch/commit-changes) (rx/from))))) -(defn update-shapes-debounce +;; Accumulates the update shapes changes into a single commit-changes +;; The accumulation is marked between the events `start` and `stop` in between +;; those events all the `update-shapes` will be agregated together with this event. +;; After a `stop` arrives the `commit` will send the changes at the same time. +(defn update-shapes-buffer ([ids update-fn] - (update-shapes-debounce ids update-fn nil)) + (update-shapes-buffer ids update-fn nil)) ([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-touched undo-group with-objects? changed-sub-attr] @@ -83,17 +87,17 @@ with-objects? false} :as props}] (let [cur-event (js/Symbol)] - (ptk/reify ::update-shapes-debounce + (ptk/reify ::update-shapes-buffer ptk/UpdateEvent (update [it state] - (if (nil? (::update-shapes-debounce-event state)) - (assoc state ::update-shapes-debounce-event cur-event) + (if (nil? (::update-shapes-buffer-event state)) + (assoc state ::update-shapes-buffer-event cur-event) (let [page-id (or page-id (get state :current-page-id)) objects (dsh/lookup-page-objects state page-id)] (update-in state - [::update-shapes-debounce-changes page-id] + [::update-shapes-buffer-changes page-id] (fn [changes] (-> (or changes (-> (pcb/empty-changes it page-id) @@ -114,21 +118,21 @@ (cond-> reg-objects? (pcb/resize-parents ids)))))))) ptk/WatchEvent (watch [_ state stream] - (if (= (::update-shapes-debounce-event state) cur-event) - (let [stopper (->> stream (rx/filter (ptk/type? ::update-shapes-debounce-stop)))] + (if (= (::update-shapes-buffer-event state) cur-event) + (let [stopper (->> stream (rx/filter (ptk/type? ::update-shapes-buffer-stop)))] (rx/concat (rx/merge (->> stream - (rx/filter (ptk/type? ::update-shapes-debounce)) + (rx/filter (ptk/type? ::update-shapes-buffer)) (rx/take-until stopper) (rx/last) - (rx/map #(update-shapes-debounce-commit))) + (rx/map #(update-shapes-buffer-commit))) - (rx/of (update-shapes-debounce ids update-fn props))) + (rx/of (update-shapes-buffer ids update-fn props))) (rx/of #(dissoc % - ::update-shapes-debounce-changes - ::update-shapes-debounce-event)))) + ::update-shapes-buffer-changes + ::update-shapes-buffer-event)))) (rx/empty))))))) (defn update-shapes @@ -151,8 +155,8 @@ ptk/WatchEvent (watch [it state _] - (if (::update-shapes-debounce state) - (rx/of (update-shapes-debounce ids update-fn props)) + (if (::update-shapes-buffer state) + (rx/of (update-shapes-buffer ids update-fn props)) (let [page-id (or page-id (get state :current-page-id)) objects (dsh/lookup-page-objects state page-id) diff --git a/frontend/src/app/main/data/workspace/tokens/application.cljs b/frontend/src/app/main/data/workspace/tokens/application.cljs index 616e8eb0fa..460c394aa0 100644 --- a/frontend/src/app/main/data/workspace/tokens/application.cljs +++ b/frontend/src/app/main/data/workspace/tokens/application.cljs @@ -495,8 +495,8 @@ (watch [_ _ _] (when (number? value) (rx/of - (when (:width attributes) (dwtr/update-dimensions shape-ids :width value {:ignore-touched true :page-id page-id :no-wasm true})) - (when (:height attributes) (dwtr/update-dimensions shape-ids :height value {:ignore-touched true :page-id page-id :no-wasm true})))))))) + (when (:width attributes) (dwtr/update-dimensions shape-ids :width value {:ignore-touched true :page-id page-id :no-wasm? true})) + (when (:height attributes) (dwtr/update-dimensions shape-ids :height value {:ignore-touched true :page-id page-id :no-wasm? true})))))))) (defn- attributes->actions [{:keys [value shape-ids attributes page-id]}] diff --git a/frontend/src/app/main/data/workspace/tokens/propagation.cljs b/frontend/src/app/main/data/workspace/tokens/propagation.cljs index 7920848c72..42e642571f 100644 --- a/frontend/src/app/main/data/workspace/tokens/propagation.cljs +++ b/frontend/src/app/main/data/workspace/tokens/propagation.cljs @@ -200,7 +200,15 @@ (let [undo-id (js/Symbol)] (rx/concat (rx/of (dwu/start-undo-transaction undo-id :timeout false)) - (rx/of (dwsh/update-shapes-debounce-start)) - (propagate-tokens state sd-tokens) - (rx/of (dwsh/update-shapes-debounce-stop)) + + ;; FIXME: now the tokens propagations is done by accumulating the update-shapes + ;; into a single commit-changes. This is not really the best way, the token application + ;; should be done with a changes_builder and sending only one `commit-changes` instead + ;; of creating lots of `update-shapes`. + (rx/of (dwsh/update-shapes-buffer-start)) + (->> (propagate-tokens state sd-tokens) + (rx/catch #(rx/concat + (rx/of (dwsh/update-shapes-buffer-stop)) + (rx/throw %)))) + (rx/of (dwsh/update-shapes-buffer-stop)) (rx/of (dwu/commit-undo-transaction undo-id))))))))))) diff --git a/frontend/src/app/main/data/workspace/wasm_text.cljs b/frontend/src/app/main/data/workspace/wasm_text.cljs index 0d34c1b2fe..9a18d0d83a 100644 --- a/frontend/src/app/main/data/workspace/wasm_text.cljs +++ b/frontend/src/app/main/data/workspace/wasm_text.cljs @@ -201,11 +201,11 @@ (let [resize-stream (->> (rx/from ids) (rx/map resize-wasm-text-debounce))] - (if (::dwsh/update-shapes-debounce state) + (if (::dwsh/update-shapes-buffer state) ;; If we're in the middle of a token propagation we wait until is finished to ;; recalculate the text sizes (->> stream - (rx/filter (ptk/type? ::dwsh/update-shapes-debounce-commit)) + (rx/filter (ptk/type? ::dwsh/update-shapes-buffer-commit)) (rx/take 1) (rx/mapcat (constantly resize-stream))) resize-stream)))))