Repository: penpot/penpot
File: frontend/src/app/render_wasm/shape.cljs (ClojureScript)

Code before:
      :layout-grid-cells
      (api/set-grid-layout-cells v)

      (:layout
       :layout-flex-dir
       :layout-gap-type
       :layout-gap
       :layout-align-items
       :layout-align-content
       :layout-justify-items
       :layout-justify-content
       :layout-wrap-type
       :layout-padding-type
       :layout-padding)
      (cond
        (ctl/grid-layout? shape)
        (api/set-grid-layout-data shape)

        (ctl/flex-layout? shape)
        (api/set-flex-layout shape))

      nil)))

(defn set-wasm-multi-attrs!
  [shape properties]
  (when (shape-in-current-page? (:id shape))
    (api/use-shape (:id shape))
    (let [result
          (->> properties
               (mapcat #(set-wasm-single-attr! shape %)))
          pending (-> (d/index-by :key :callback result) vals)]
      (if (and pending (seq pending))
        (->> (rx/from pending)
             (rx/mapcat (fn [callback] (callback)))
             (rx/reduce conj [])
             (rx/subs!
              (fn [_]
                (api/update-shape-tiles)
                (api/clear-drawing-cache)
                (api/request-render "set-wasm-attrs-pending"))))
        (do
          (api/update-shape-tiles)
          (api/request-render "set-wasm-attrs"))))))

(defn set-wasm-attrs!
  [shape k v]
  (when (shape-in-current-page? (:id shape))
    (let [shape (assoc shape k v)]
      (api/use-shape (:id shape))
      (let [result (set-wasm-single-attr! shape k)
            pending (-> (d/index-by :key :callback result) vals)]

Review comment (performance):
The shape id should be retrieved with `(dm/get-prop shape :id)`. Is the most efficient way to do it.

Code after:
      :layout-grid-columns
      (api/set-grid-layout-columns v)

      :layout-grid-cells
      (api/set-grid-layout-cells v)

      (:layout
       :layout-flex-dir
       :layout-gap-type
       :layout-gap
       :layout-align-items
       :layout-align-content
       :layout-justify-items
       :layout-justify-content
       :layout-wrap-type
       :layout-padding-type
       :layout-padding)
      (cond
        (ctl/grid-layout? shape)
        (api/set-grid-layout-data shape)

        (ctl/flex-layout? shape)
        (api/set-flex-layout shape))

      nil)))

(defn set-wasm-multi-attrs!
  [shape properties]
  (let [shape-id (dm/get-prop shape :id)]
    (when (shape-in-current-page? shape-id)
      (api/use-shape shape-id)
      (let [result
            (->> properties
                 (mapcat #(set-wasm-single-attr! shape %)))
            pending (-> (d/index-by :key :callback result) vals)]
        (if (and pending (seq pending))
          (->> (rx/from pending)
               (rx/mapcat (fn [callback] (callback)))
               (rx/reduce conj [])
               (rx/subs!
                (fn [_]
                  (api/update-shape-tiles)
                  (api/clear-drawing-cache)
                  (api/request-render "set-wasm-attrs-pending"))))
          (do
            (api/update-shape-tiles)
            (api/request-render "set-wasm-attrs")))))))

(defn set-wasm-attrs!
  [shape k v]
  (let [shape-id (dm/get-prop shape :id)]