What is the difference between using swap!
and reset!
in Clojure functions? I have seen from the clojure.core docs that they are used to change the value of an atom but I am not sure when to use swap!
and when to use reset!
.
What circumstances would you use swap!
and which circumstances would you use reset!
?
[:input {:type "text"
:value @time-color
:on-change #(reset! time-color (-> % .-target .-value))}]
The above code is an example of using reset!
for a button
[:input.form-control
{:type :text
:name :ric
:on-change #(swap! fields assoc :ric (-> % .-target .-value))
:value (:ric @fields)}]
And this button uses swap!
Are swap!
and reset!
interchangeable?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…