Update shapes in one undo step, resolve tokens from state not cache atom

This commit is contained in:
Florian Schroedl 2024-08-01 09:13:58 +02:00
parent a1fefe66ae
commit e52623c728

View file

@ -1,16 +1,17 @@
(ns app.main.ui.workspace.tokens.update (ns app.main.ui.workspace.tokens.update
(:require (:require
[beicon.v2.core :as brx]
[app.common.types.token :as ctt] [app.common.types.token :as ctt]
[app.main.data.workspace.shape-layout :as dwsl] [app.main.data.workspace.shape-layout :as dwsl]
[app.main.data.workspace.undo :as dwu]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.workspace.tokens.changes :as wtch] [app.main.ui.workspace.tokens.changes :as wtch]
[app.main.ui.workspace.tokens.style-dictionary :as wtsd] [app.main.ui.workspace.tokens.style-dictionary :as wtsd]
[app.main.ui.workspace.tokens.style-dictionary :as sd]
[beicon.v2.core :as rx]
[clojure.data :as data] [clojure.data :as data]
[clojure.set :as set] [clojure.set :as set]
[potok.v2.core :as ptk] [potok.v2.core :as ptk]))
[beicon.v2.core :as rx]))
;; Constants ------------------------------------------------------------------- ;; Constants -------------------------------------------------------------------
@ -107,20 +108,32 @@
update-infos))) update-infos)))
shapes-update-info)) shapes-update-info))
(defn update-workspace-tokens [] (defn update-tokens [resolved-tokens]
(let [resolved-tokens (wtsd/get-cached-tokens @refs/workspace-tokens)]
(->> @refs/workspace-page-objects (->> @refs/workspace-page-objects
(collect-shapes-update-info resolved-tokens) (collect-shapes-update-info resolved-tokens)
(actionize-shapes-update-info)))) (actionize-shapes-update-info)))
(defn update-workspace-tokens []
(let [resolved-tokens (wtsd/get-cached-tokens @refs/workspace-tokens)]
(update-tokens resolved-tokens)))
(defn update-workspace-tokens-event [] (defn update-workspace-tokens-event []
(ptk/reify ::update-shape-position (ptk/reify ::update-shape-position
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ state _]
(->> (update-workspace-tokens) (->>
(mapv (fn [[f & attrs]] (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens])))
(rx/mapcat
(fn [sd-tokens]
(let [undo-id (js/Symbol)]
(rx/concat
(rx/of (dwu/start-undo-transaction undo-id))
(rx/concat
(->> (update-tokens sd-tokens)
(map (fn [[f & attrs]]
(apply f attrs))) (apply f attrs)))
(brx/concat))))) (rx/concat)))
(rx/of (dwu/commit-undo-transaction undo-id))))))))))
(comment (comment
(update-workspace-tokens) (update-workspace-tokens)