mirror of
https://github.com/penpot/penpot.git
synced 2026-09-10 05:58:47 +00:00
♻️ Refactor detach-preview-sprite! to use atomic swap
Use idiomatic atomic swap! update instead of non-atomic read-then-write pattern. The new implementation computes the decremented refs inside swap! and only removes the node when the result reaches zero. AI-assisted-by: mimo-v2.5
This commit is contained in:
parent
3ce1f083e1
commit
3acfc65894
@ -238,12 +238,9 @@
|
|||||||
the last open dropdown closes. The cached node and `:ids` stay, so reopening
|
the last open dropdown closes. The cached node and `:ids` stay, so reopening
|
||||||
re-attaches without a refetch or re-parse."
|
re-attaches without a refetch or re-parse."
|
||||||
[node]
|
[node]
|
||||||
(let [refs (max 0 (dec (:refs @preview-sprite)))]
|
(let [new-state (swap! preview-sprite update :refs #(max 0 (dec %)))]
|
||||||
(if (pos? refs)
|
(when (zero? (:refs new-state))
|
||||||
(swap! preview-sprite assoc :refs refs)
|
(dom/remove! node))))
|
||||||
(do
|
|
||||||
(dom/remove! node)
|
|
||||||
(swap! preview-sprite assoc :refs 0)))))
|
|
||||||
|
|
||||||
(defn- add-font-css!
|
(defn- add-font-css!
|
||||||
"Creates a style element and attaches it to the dom."
|
"Creates a style element and attaches it to the dom."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user