Repository: penpot/penpot
File: frontend/src/app/main/data/workspace/tokens/application.cljs (ClojureScript)

Code before:
   [app.main.data.workspace.colors :as wdc]
   [app.main.data.workspace.shape-layout :as dwsl]
   [app.main.data.workspace.shapes :as dwsh]
   [app.main.data.workspace.transforms :as dwtr]
   [app.main.data.workspace.undo :as dwu]
   [app.main.fonts :as fonts]
   [app.main.store :as st]
   [app.util.i18n :refer [tr]]
   [beicon.v2.core :as rx]
   [clojure.set :as set]
   [cuerdas.core :as str]
   [potok.v2.core :as ptk]))

(declare token-properties)
(declare update-layout-item-margin)
(declare all-attrs-appliable-for-token?)

;; Events to update the value of attributes with applied tokens ---------------------------------------------------------

;; (note that dwsh/update-shapes function returns an event)

(defn update-shape-radius-all
  ([value shape-ids attributes] (update-shape-radius-all value shape-ids attributes nil))
  ([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions
   (when (number? value)
     (if (< value 0)
       (dwsh/update-shapes shape-ids
                           (fn [shape]
                             (ctsr/set-radius-to-all-corners shape 0))
                           {:reg-objects? true
                            :ignore-touched true
                            :page-id page-id
                            :attrs ctt/border-radius-keys})
       (dwsh/update-shapes shape-ids
                           (fn [shape]
                             (ctsr/set-radius-to-all-corners shape value))
                           {:reg-objects? true
                            :ignore-touched true
                            :page-id page-id
                            :attrs ctt/border-radius-keys})))))

(defn update-shape-radius-for-corners
  ([value shape-ids attributes] (update-shape-radius-for-corners value shape-ids attributes nil))
  ([value shape-ids attributes page-id]
   (when (number? value)
     (if (< value 0)
       (dwsh/update-shapes shape-ids
                           (fn [shape]
                             (ctsr/set-radius-for-corners shape attributes 0))
                           {:reg-objects? true
                            :ignore-touched true

Review comment (suggestion):
I'd rather have done something like
```clojure
(let [value (max 0 value)]
  (dwsh/update-shapes...
```
or if you want it more explicit `(let [value (if (< value 0) 0 value)]`. To avoid duplicating the whole `update-shapes`.

Code after:
   [app.main.data.workspace.colors :as wdc]
   [app.main.data.workspace.shape-layout :as dwsl]
   [app.main.data.workspace.shapes :as dwsh]
   [app.main.data.workspace.transforms :as dwtr]
   [app.main.data.workspace.undo :as dwu]
   [app.main.fonts :as fonts]
   [app.main.store :as st]
   [app.util.i18n :refer [tr]]
   [beicon.v2.core :as rx]
   [clojure.set :as set]
   [cuerdas.core :as str]
   [potok.v2.core :as ptk]))

(declare token-properties)
(declare update-layout-item-margin)
(declare all-attrs-appliable-for-token?)

;; Events to update the value of attributes with applied tokens ---------------------------------------------------------

;; (note that dwsh/update-shapes function returns an event)

(defn update-shape-radius-all
  ([value shape-ids attributes] (update-shape-radius-all value shape-ids attributes nil))
  ([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions
   (when (number? value)
     (let [value (max 0 value)]
       (dwsh/update-shapes shape-ids
                           (fn [shape]
                             (ctsr/set-radius-to-all-corners shape value))
                           {:reg-objects? true
                            :ignore-touched true
                            :page-id page-id
                            :attrs ctt/border-radius-keys})))))

(defn update-shape-radius-for-corners
  ([value shape-ids attributes] (update-shape-radius-for-corners value shape-ids attributes nil))
  ([value shape-ids attributes page-id]
   (when (number? value)
     (let [value (max 0 value)]
       (dwsh/update-shapes shape-ids
                           (fn [shape]
                             (ctsr/set-radius-for-corners shape attributes value))
                           {:reg-objects? true
                            :ignore-touched true
                            :page-id page-id
                            :attrs ctt/border-radius-keys})))))
(defn update-opacity
  ([value shape-ids attributes] (update-opacity value shape-ids attributes nil))
  ([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions
   (when (<= 0 value 1)
     (dwsh/update-shapes shape-ids