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:
parent
73e8b80521
commit
a79d1013bf
1 changed files with 12 additions and 3 deletions
|
@ -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 ---------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue