mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 08:51:41 +02:00
Allow passing custom cache atom
This commit is contained in:
parent
908cc2240f
commit
9bc48a3a1a
1 changed files with 6 additions and 5 deletions
|
@ -91,12 +91,13 @@
|
||||||
|
|
||||||
This hook will return the unresolved tokens as state until they are processed,
|
This hook will return the unresolved tokens as state until they are processed,
|
||||||
then the state will be updated with the resolved tokens."
|
then the state will be updated with the resolved tokens."
|
||||||
[tokens]
|
[tokens & {:keys [cache-atom]
|
||||||
(let [tokens-state (mf/use-state (get @!tokens-cache tokens tokens))]
|
:or {cache-atom !tokens-cache}}]
|
||||||
|
(let [tokens-state (mf/use-state (get @cache-atom tokens tokens))]
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps tokens)
|
(mf/deps tokens)
|
||||||
(fn []
|
(fn []
|
||||||
(let [cached (get @!tokens-cache tokens)]
|
(let [cached (get @cache-atom tokens)]
|
||||||
(cond
|
(cond
|
||||||
;; The tokens are already processing somewhere
|
;; The tokens are already processing somewhere
|
||||||
(p/promise? cached) (p/then cached #(reset! tokens-state %))
|
(p/promise? cached) (p/then cached #(reset! tokens-state %))
|
||||||
|
@ -104,9 +105,9 @@
|
||||||
(some? cached) (reset! tokens-state cached)
|
(some? cached) (reset! tokens-state cached)
|
||||||
;; No cached entry, start processing
|
;; No cached entry, start processing
|
||||||
:else (let [promise+ (resolve-tokens+ tokens)]
|
:else (let [promise+ (resolve-tokens+ tokens)]
|
||||||
(swap! !tokens-cache assoc tokens promise+)
|
(swap! cache-atom assoc tokens promise+)
|
||||||
(p/then promise+ (fn [resolved-tokens]
|
(p/then promise+ (fn [resolved-tokens]
|
||||||
(swap! !tokens-cache assoc tokens resolved-tokens)
|
(swap! cache-atom assoc tokens resolved-tokens)
|
||||||
(reset! tokens-state resolved-tokens))))))))
|
(reset! tokens-state resolved-tokens))))))))
|
||||||
@tokens-state))
|
@tokens-state))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue