function | since v0.0-927 | clojure.core/reset! | Edit |
(reset! a new-value)
Sets the value of atom a
to new-value
without regard for the current value.
Returns new-value
.
Sets the value of atom to newval without regard for the current value. Returns new-value.
(defn reset!
[a new-value]
(if (instance? Atom a)
(let [validate (.-validator a)]
(when-not (nil? validate)
(when-not (validate new-value)
(throw (js/Error. "Validator rejected reference state"))))
(let [old-value (.-state a)]
(set! (.-state a) new-value)
(when-not (nil? (.-watches a))
(-notify-watches a old-value new-value))
new-value))
(-reset! a new-value)))