0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Prevent reprocessing the style-dictionary cache multiple times

This commit is contained in:
Florian Schroedl 2024-06-12 16:45:24 +02:00
parent 73e8b80521
commit a79d1013bf

View file

@ -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 ---------------------------------------------------------------------