mirror of
https://github.com/penpot/penpot.git
synced 2026-08-26 14:48:43 +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
|
||||
re-attaches without a refetch or re-parse."
|
||||
[node]
|
||||
(let [refs (max 0 (dec (:refs @preview-sprite)))]
|
||||
(if (pos? refs)
|
||||
(swap! preview-sprite assoc :refs refs)
|
||||
(do
|
||||
(dom/remove! node)
|
||||
(swap! preview-sprite assoc :refs 0)))))
|
||||
(let [new-state (swap! preview-sprite update :refs #(max 0 (dec %)))]
|
||||
(when (zero? (:refs new-state))
|
||||
(dom/remove! node))))
|
||||
|
||||
(defn- add-font-css!
|
||||
"Creates a style element and attaches it to the dom."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user