Extract token apply function

This commit is contained in:
Florian Schroedl 2024-05-16 09:02:48 +02:00
parent 4e3af1407d
commit cdca00a986

View file

@ -55,15 +55,20 @@
(->> (map (fn [attr] [attr token-id]) attributes) (->> (map (fn [attr] [attr token-id]) attributes)
(into {}))) (into {})))
(defn apply-token-id [{:keys [shape token-id attributes]}]
(let [token (token-from-attributes token-id attributes)]
(toggle-or-apply-token shape token)))
(defn update-token-from-attributes (defn update-token-from-attributes
[{:keys [token-id shape-id attributes]}] [{:keys [token-id shape-id attributes]}]
(ptk/reify ::update-token-from-attributes (ptk/reify ::update-token-from-attributes
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [shape (get-shape-from-state shape-id state) (let [shape (get-shape-from-state shape-id state)
token (token-from-attributes token-id attributes) applied-tokens (apply-token-id {:shape shape
next-applied-tokens (toggle-or-apply-token shape token)] :token-id token-id
(rx/of (update-shape shape-id {:applied-tokens next-applied-tokens})))))) :attributes attributes})]
(rx/of (update-shape shape-id {:applied-tokens applied-tokens}))))))
(defn add-token (defn add-token
[token] [token]