0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 14:12:36 -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/use-effect
(mf/deps tokens) (mf/deps tokens)
(fn [] (fn []
(p/let [resolved-tokens (resolve-tokens+ tokens)] (let [cached (get @!tokens-cache tokens)]
(reset! !tokens-cache resolved-tokens) (cond
(reset! tokens-state resolved-tokens)))) ;; 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)) @tokens-state))
;; Testing --------------------------------------------------------------------- ;; Testing ---------------------------------------------------------------------