mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
Remove caching layer for now
This commit is contained in:
parent
d0f8e9612a
commit
6e9623153c
1 changed files with 24 additions and 31 deletions
|
@ -59,11 +59,8 @@
|
||||||
;; Component -------------------------------------------------------------------
|
;; Component -------------------------------------------------------------------
|
||||||
|
|
||||||
(defn use-debonced-resolve-callback
|
(defn use-debonced-resolve-callback
|
||||||
[name-ref token tokens callback & {:keys [cached timeout]
|
[name-ref token tokens callback & {:keys [timeout] :or {timeout 160}}]
|
||||||
:or {cached {}
|
|
||||||
timeout 160}}]
|
|
||||||
(let [timeout-id-ref (mf/use-ref nil)
|
(let [timeout-id-ref (mf/use-ref nil)
|
||||||
cache (mf/use-ref cached)
|
|
||||||
debounced-resolver-callback
|
debounced-resolver-callback
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps token callback tokens)
|
(mf/deps token callback tokens)
|
||||||
|
@ -76,33 +73,29 @@
|
||||||
(js/setTimeout
|
(js/setTimeout
|
||||||
(fn []
|
(fn []
|
||||||
(when (not (timeout-outdated-cb?))
|
(when (not (timeout-outdated-cb?))
|
||||||
(if-let [cached (get (mf/ref-val cache) tokens)]
|
(let [token-references (sd/find-token-references input)
|
||||||
(callback cached)
|
;; When creating a new token we dont have a token name yet,
|
||||||
(let [token-references (sd/find-token-references input)
|
;; so we use a temporary token name that hopefully doesn't clash with any of the users token names.
|
||||||
;; When creating a new token we dont have a token name yet,
|
token-name (if (empty? @name-ref) "__TOKEN_STUDIO_SYSTEM.TEMP" @name-ref)
|
||||||
;; so we use a temporary token name that hopefully doesn't clash with any of the users token names.
|
direct-self-reference? (get token-references token-name)
|
||||||
token-name (if (empty? @name-ref) "__TOKEN_STUDIO_SYSTEM.TEMP" @name-ref)
|
empty-input? (empty? (str/trim input))]
|
||||||
direct-self-reference? (get token-references token-name)
|
(cond
|
||||||
empty-input? (empty? (str/trim input))]
|
empty-input? (callback nil)
|
||||||
(cond
|
direct-self-reference? (callback :error/token-direct-self-reference)
|
||||||
empty-input? (callback nil)
|
:else
|
||||||
direct-self-reference? (callback :error/token-direct-self-reference)
|
(let [token-id (or (:id token) (random-uuid))
|
||||||
:else
|
new-tokens (update tokens token-id merge {:id token-id
|
||||||
(let [token-id (or (:id token) (random-uuid))
|
:value input
|
||||||
new-tokens (update tokens token-id merge {:id token-id
|
:name token-name})]
|
||||||
:value input
|
(-> (sd/resolve-tokens+ new-tokens)
|
||||||
:name token-name})]
|
(p/finally
|
||||||
(-> (sd/resolve-tokens+ new-tokens)
|
(fn [resolved-tokens _err]
|
||||||
(p/finally
|
(when-not (timeout-outdated-cb?)
|
||||||
(fn [resolved-tokens _err]
|
(let [{:keys [errors resolved-value] :as resolved-token} (get resolved-tokens token-id)]
|
||||||
(when-not (timeout-outdated-cb?)
|
(cond
|
||||||
(let [{:keys [errors resolved-value] :as resolved-token} (get resolved-tokens token-id)]
|
resolved-value (callback resolved-token)
|
||||||
(cond
|
(= #{:style-dictionary/missing-reference} errors) (callback :error/token-missing-reference)
|
||||||
resolved-value (do
|
:else (callback :error/unknown-error))))))))))))
|
||||||
(mf/set-ref-val! cache (assoc (mf/ref-val cache) input resolved-tokens))
|
|
||||||
(callback resolved-token))
|
|
||||||
(= #{:style-dictionary/missing-reference} errors) (callback :error/token-missing-reference)
|
|
||||||
:else (callback :error/unknown-error)))))))))))))
|
|
||||||
|
|
||||||
timeout))))]
|
timeout))))]
|
||||||
debounced-resolver-callback))
|
debounced-resolver-callback))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue