Is it safe to deref an external atom inside an event handler? #800
-
Hi all, Propose I have the following code: (def !monkey-business (atom 69))
(reg-event-fx
:harvest-banana
(fn [{:keys [db]}]
(let [number-of-bananas @!monkey-business
max-bananas 420]
(if (>= number-of-bananas max-bananas)
{:db (assoc db :alert "Too many bananas!")
:dispatch [:throw-a-fit]}
{::do-harvest-banana nil}))))
(reg-fx
::do-harvest-banana
(fn []
(swap! !monkey-business inc))) Is it safe for me to deref the I've been only deref'ing atoms inside fx handlers just to be safe, but things can get convoluted very quickly and I'd like to keep the dispatch flow easier to follow. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@JordanSkousen Atoms read or modified in a fx handler should be fine, assuming all atoms are only modified via re-frame event handlers. However this raises a fundamental design question: Why is this state managed outside of app-db in other atoms as opposed to properties app-db |
Beta Was this translation helpful? Give feedback.
@JordanSkousen Atoms read or modified in a fx handler should be fine, assuming all atoms are only modified via re-frame event handlers.
However this raises a fundamental design question: Why is this state managed outside of app-db in other atoms as opposed to properties app-db
db
?