mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 08:09:14 -05:00
Add hook for using resolved tokens cache
This commit is contained in:
parent
0921f8043b
commit
2f45ab1b62
2 changed files with 18 additions and 1 deletions
|
@ -26,6 +26,7 @@
|
|||
[app.main.ui.icons :as i]
|
||||
[app.main.ui.workspace.tokens.core :as wtc]
|
||||
[app.main.ui.workspace.tokens.editable-select :refer [editable-select]]
|
||||
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[clojure.set :refer [rename-keys union]]
|
||||
|
@ -98,7 +99,8 @@
|
|||
selection-parents-ref (mf/use-memo (mf/deps ids) #(refs/parents-by-ids ids))
|
||||
selection-parents (mf/deref selection-parents-ref)
|
||||
|
||||
tokens (mf/deref refs/workspace-tokens)
|
||||
tokens (-> (mf/deref refs/workspace-tokens)
|
||||
(sd/use-resolved-tokens))
|
||||
tokens-by-type (mf/use-memo (mf/deps tokens) #(wtc/group-tokens-by-type tokens))
|
||||
|
||||
border-radius-tokens (:border-radius tokens-by-type)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(:require
|
||||
[app.main.refs :as refs]
|
||||
[promesa.core :as p]
|
||||
[rumext.v2 :as mf]
|
||||
[shadow.resource]))
|
||||
|
||||
(def StyleDictionary
|
||||
|
@ -81,6 +82,20 @@
|
|||
(when-let [workspace-tokens @refs/workspace-tokens]
|
||||
(resolve-tokens+ workspace-tokens)))
|
||||
|
||||
;; Hooks -----------------------------------------------------------------------
|
||||
|
||||
(defonce !tokens-cache (atom nil))
|
||||
|
||||
(defn use-resolved-tokens [tokens]
|
||||
(let [tokens-state (mf/use-state (get @!tokens-cache tokens tokens))]
|
||||
(mf/use-effect
|
||||
(mf/deps tokens)
|
||||
(fn []
|
||||
(p/let [resolved-tokens (resolve-tokens+ tokens)]
|
||||
(reset! !tokens-cache resolved-tokens)
|
||||
(reset! tokens-state resolved-tokens))))
|
||||
@tokens-state))
|
||||
|
||||
;; Testing ---------------------------------------------------------------------
|
||||
|
||||
(defn tokens-studio-example []
|
||||
|
|
Loading…
Add table
Reference in a new issue