From 5a358e3d0cfa43efb3772846b0ad8d3b9175f8c3 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 5 Jul 2024 14:13:14 +0200 Subject: [PATCH] Extract singular token applied predicate --- .../app/main/ui/workspace/tokens/token.cljs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 79fbb0e2d7..3cb8e1ff1a 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -18,17 +18,24 @@ applied-tokens) (into {})))) +(defn token-attribute-applied? + "Test if `token` is applied to a `shape` on single `token-attribute`." + [token shape token-attribute] + (when-let [id (get-in shape [:applied-tokens token-attribute])] + (= (:id token) id))) + (defn token-applied? - "Test if `token` is applied to a `shape` with the given `token-attributes`." + "Test if `token` is applied to a `shape` with at least one of the one of the given `token-attributes`." [token shape token-attributes] - (let [{:keys [id]} token - applied-tokens (get shape :applied-tokens {})] - (some (fn [attr] - (= (get applied-tokens attr) id)) - token-attributes))) + (some #(token-attribute-applied? token shape %) token-attributes)) (defn shapes-token-applied? - "Test if `token` is applied to to any of `shapes` with the given `token-attributes`." + "Test if `token` is applied to to any of `shapes` with at least one of the one of the given `token-attributes`." + [token shapes token-attributes] + (some #(token-applied? token % token-attributes) shapes)) + +(defn shapes-token-applied-all? + "Test if `token` is applied to to any of `shapes` with at least one of the one of the given `token-attributes`." [token shapes token-attributes] (some #(token-applied? token % token-attributes) shapes))