From a79d1013bfff824dd1dc24341236bd294be8dffd Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 12 Jun 2024 16:45:24 +0200 Subject: [PATCH] Prevent reprocessing the style-dictionary cache multiple times --- .../ui/workspace/tokens/style_dictionary.cljs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs index 77e891b62..d0dda4779 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -91,9 +91,18 @@ (mf/use-effect (mf/deps tokens) (fn [] - (p/let [resolved-tokens (resolve-tokens+ tokens)] - (reset! !tokens-cache resolved-tokens) - (reset! tokens-state resolved-tokens)))) + (let [cached (get @!tokens-cache tokens)] + (cond + ;; The tokens are already processing somewhere + (p/promise? cached) (p/then cached #(reset! tokens-state %)) + ;; Get the cached entry + (some? cached) (reset! tokens-state cached) + ;; No cached entry, start processing + :else (let [promise+ (resolve-tokens+ tokens)] + (swap! !tokens-cache assoc tokens promise+) + (p/then promise+ (fn [resolved-tokens] + (swap! !tokens-cache assoc tokens resolved-tokens) + (reset! tokens-state resolved-tokens)))))))) @tokens-state)) ;; Testing ---------------------------------------------------------------------