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

Code before:
                                       (->> (cfh/get-parents-with-self objects frame-id)
                                            (some ctk/is-variant?)))
            add-new-variant? (and
                             ;; The parent is a variant container
                              (-> frame-id objects ctk/is-variant-container?)
                             ;; Any of the shapes is a main instance
                              (some (comp ctk/main-instance? objects) ids))]

        (rx/concat
         (let [shapes  (mapv #(get objects %) ids)
               moved-count (count (filter #(not= (:parent-id %) frame-id) shapes))
               emit-layout-event? (and (cfh/has-layout? objects frame-id)
                                       (pos? moved-count))]
           (when emit-layout-event?
             (rx/of (ev/event {::ev/name "layout-add-element"
                               ::ev/origin "workspace:move-shapes-to-frame"
                               :element-type (cfh/get-selected-type objects ids)
                               :moved moved-count}))))

         (when (and (some? frame-id) (d/not-empty? changes))
           (rx/of (dch/commit-changes changes)
                  (dwc/expand-collapse frame-id)))
         (when add-component-to-variant?
           (rx/of (ptk/event ::ev/event {::ev/name "add-component-to-variant"})))
         (when add-new-variant?
           (rx/of (ptk/event ::ev/event {::ev/name "add-new-variant" :trigger "move-shapes-in-workspace"}))))))))

(defn- get-displacement
  "Retrieve the correct displacement delta point for the
  provided direction speed and distances thresholds."
  [direction]
  (case direction
    :up (gpt/point 0 (- 1))
    :down (gpt/point 0 1)
    :left (gpt/point (- 1) 0)
    :right (gpt/point 1 0)))


;; -- Flip ----------------------------------------------------------

(defn flip-horizontal-selected
  ([]
   (flip-horizontal-selected nil))
  ([ids]
   (ptk/reify ::flip-horizontal-selected
     ptk/WatchEvent
     (watch [_ state _]
       (let [objects   (dsh/lookup-page-objects state)
             selected  (or ids (dsh/lookup-selected state {:omit-blocked? true}))
             shapes    (->> selected
                            (map (d/getf objects))

Review comment (suggestion):
The same, and the origin can be added to both events.
Also, there is a simplified event construction: `(ev/event {::ev/name ... })`

Code after:
            add-new-variant? (and
                             ;; The parent is a variant container
                              (-> frame-id objects ctk/is-variant-container?)
                             ;; Any of the shapes is a main instance
                              (some (comp ctk/main-instance? objects) ids))]

        (rx/concat
         (let [shapes  (mapv #(get objects %) ids)
               moved-count (count (filter #(not= (:parent-id %) frame-id) shapes))
               emit-layout-event? (and (cfh/has-layout? objects frame-id)
                                       (pos? moved-count))]
           (when emit-layout-event?
             (rx/of (ev/event {::ev/name "layout-add-element"
                               ::ev/origin "workspace:move-shapes-to-frame"
                               :element-type (cfh/get-selected-type objects ids)
                               :moved moved-count}))))

         (when (and (some? frame-id) (d/not-empty? changes))
           (rx/of (dch/commit-changes changes)
                  (dwc/expand-collapse frame-id)))
         (when add-component-to-variant?
           (rx/of (ev/event {::ev/name "add-component-to-variant"})))
         (when add-new-variant?
           (rx/of (ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:move-shapes-to-frame"}))))))))

(defn- get-displacement
  "Retrieve the correct displacement delta point for the
  provided direction speed and distances thresholds."
  [direction]
  (case direction
    :up (gpt/point 0 (- 1))
    :down (gpt/point 0 1)
    :left (gpt/point (- 1) 0)
    :right (gpt/point 1 0)))


;; -- Flip ----------------------------------------------------------


(defn flip-horizontal-selected
  ([]
   (flip-horizontal-selected nil))
  ([ids]
   (ptk/reify ::flip-horizontal-selected
     ptk/WatchEvent
     (watch [_ state _]
       (let [objects   (dsh/lookup-page-objects state)
             selected  (or ids (dsh/lookup-selected state {:omit-blocked? true}))
             shapes    (->> selected
                            (map (d/getf objects))
                            (remove ctk/is-variant-container?))