mirror of
https://github.com/penpot/penpot.git
synced 2025-07-25 17:57:12 +02:00
Async token event tests working
This commit is contained in:
parent
e203646085
commit
ed7aad6c4e
4 changed files with 90 additions and 49 deletions
|
@ -60,15 +60,19 @@
|
|||
shapes)]
|
||||
(and (empty? with-token) (seq without-token))))
|
||||
|
||||
(defn apply-token
|
||||
"Applies `attributes` to `token` for `shapes-ids`.
|
||||
|
||||
When a `on-shape-update` function is passed, use this to update the shape attributes as well."
|
||||
[{:keys [attributes token shape-ids on-update-shape] :as _props}]
|
||||
(ptk/reify ::apply-token
|
||||
(defn done
|
||||
[]
|
||||
(ptk/reify ::done
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(->> (rx/from (sd/resolve-workspace-tokens+))
|
||||
(rx/from (p/resolved true)))))
|
||||
|
||||
(defn apply-token
|
||||
[{:keys [attributes shape-ids token on-update-shape cb] :as _props}]
|
||||
(ptk/reify ::apply-token
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens])))
|
||||
(rx/mapcat
|
||||
(fn [sd-tokens]
|
||||
(let [resolved-value (-> (get sd-tokens (:id token))
|
||||
|
@ -77,8 +81,13 @@
|
|||
(into {}))]
|
||||
(rx/of
|
||||
(dch/update-shapes shape-ids (fn [shape] (update shape :applied-tokens merge tokenized-attributes)))
|
||||
(when cb
|
||||
(cb))
|
||||
(when on-update-shape
|
||||
(on-update-shape resolved-value shape-ids attributes))))))))))
|
||||
(on-update-shape resolved-value shape-ids attributes))))
|
||||
#_(rx/of
|
||||
(dch/update-shapes shape-ids #(assoc % :applied-tokens {:found 1})))))))))
|
||||
|
||||
|
||||
(def remove-keys #(apply dissoc %1 %2))
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
"Resolves references and math expressions using StyleDictionary.
|
||||
Returns a promise with the resolved dictionary."
|
||||
[tokens & {:keys [debug?] :as config}]
|
||||
(let [performance-start (js/window.performance.now)
|
||||
(let [#_#_performance-start (js/window.performance.now)
|
||||
sd (tokens->style-dictionary+ tokens config)]
|
||||
(when debug?
|
||||
(js/console.log "StyleDictionary" sd))
|
||||
|
@ -61,12 +61,12 @@
|
|||
(.buildAllPlatforms "json")
|
||||
(.catch js/console.error)
|
||||
(.then (fn [^js resp]
|
||||
(let [performance-end (js/window.performance.now)
|
||||
duration-ms (- performance-end performance-start)
|
||||
(let [#_#_performance-end (js/window.performance.now)
|
||||
#_#_duration-ms (- performance-end performance-start)
|
||||
resolved-tokens (.-allTokens resp)]
|
||||
(when debug?
|
||||
(js/console.log "Time elapsed" duration-ms "ms")
|
||||
(js/console.log "Resolved tokens" resolved-tokens))
|
||||
#_(when debug?
|
||||
(js/console.log "Time elapsed" duration-ms "ms")
|
||||
(js/console.log "Resolved tokens" resolved-tokens))
|
||||
resolved-tokens))))))
|
||||
|
||||
(defn humanize-errors [{:keys [errors value] :as _token}]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue