From 053d0fc923d0f82008c552df62e2d0d50950854c Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 10:15:35 +0200 Subject: [PATCH] Cleanup function --- common/src/app/common/types/tokens_lib.cljc | 17 +++++++++-------- .../common_tests/types/tokens_lib_test.cljc | 9 +++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 2b355a249..b43ac7fd5 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -627,16 +627,17 @@ (get-active-themes this))) (get-active-themes-set-tokens [this] - (let [sets-order (get-sets-order this)] + (let [sets-order (get-sets-order this) + active-themes (get-active-themes this) + order-theme-set (fn [theme] + (filter #(contains? (set (:sets theme)) %) sets-order))] (reduce - (fn [acc cur] + (fn [tokens theme] (reduce - (fn [acc cur] - (merge acc (:tokens (get-set this cur)))) - acc - (let [ref-set (set (:sets cur))] - (filter #(contains? ref-set %) sets-order)))) - (d/ordered-map) (get-active-themes this)))) + (fn [tokens' cur] + (merge tokens' (:tokens (get-set this cur)))) + tokens (order-theme-set theme))) + (d/ordered-map) active-themes))) (update-set-name [_ old-set-name new-set-name] (TokensLib. sets diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 4c7dd8a7a..945504e69 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -337,7 +337,7 @@ (ctob/add-token-in-set "set-b" (ctob/make-token :name "set-b-token" :type :boolean :value true)) - + ;; Ignore this set (ctob/add-set (ctob/make-token-set :name "inactive-set")) (ctob/add-token-in-set "inactive-set" (ctob/make-token :name "inactive-set-token" :type :boolean @@ -345,9 +345,10 @@ expected-order (ctob/get-sets-order tokens-lib) - expected-tokens (ctob/get-active-themes-set-tokens tokens-lib)] - (t/is (= expected-order '("set-a" "set-b"))) - (t/is (= ["set-a-token" "set-b-token"] (map key expected-tokens)))))) + expected-tokens (ctob/get-active-themes-set-tokens tokens-lib) + expected-token-names (mapv key expected-tokens)] + (t/is (= '("set-a" "set-b" "inactive-set") expected-order)) + (t/is (= ["set-a-token" "set-b-token"] expected-token-names))))) (t/testing "token-theme in a lib"