@@ -4569,15 +4569,17 @@ reduces them without incurring seq initialization"
45694569 atom before and after the reset."
45704570 {:added " 1.9" }
45714571 [a new-value]
4572- (let [validate (.-validator a)]
4573- (when-not (nil? validate)
4574- (when-not (validate new-value)
4575- (throw (js/Error. " Validator rejected reference state" ))))
4576- (let [old-value (.-state a)]
4577- (set! (.-state a) new-value)
4578- (when-not (nil? (.-watches a))
4579- (-notify-watches a old-value new-value))
4580- [old-value new-value])))
4572+ (if (instance? Atom a)
4573+ (let [validate (.-validator a)]
4574+ (when-not (nil? validate)
4575+ (when-not (validate new-value)
4576+ (throw (js/Error. " Validator rejected reference state" ))))
4577+ (let [old-value (.-state a)]
4578+ (set! (.-state a) new-value)
4579+ (when-not (nil? (.-watches a))
4580+ (-notify-watches a old-value new-value))
4581+ [old-value new-value]))
4582+ [(-deref a) (-reset! a new-value)]))
45814583
45824584(defn swap!
45834585 " Atomically swaps the value of atom to be:
@@ -4608,13 +4610,21 @@ reduces them without incurring seq initialization"
46084610 Returns [old new], the value of the atom before and after the swap."
46094611 {:added " 1.9" }
46104612 ([a f]
4611- (reset-vals! a (f (.-state a))))
4613+ (if (instance? Atom a)
4614+ (reset-vals! a (f (.-state a)))
4615+ [(-deref a) (-swap! a f)]))
46124616 ([a f x]
4613- (reset-vals! a (f (.-state a) x)))
4617+ (if (instance? Atom a)
4618+ (reset-vals! a (f (.-state a) x))
4619+ [(-deref a) (-swap! a f x)]))
46144620 ([a f x y]
4615- (reset-vals! a (f (.-state a) x y)))
4621+ (if (instance? Atom a)
4622+ (reset-vals! a (f (.-state a) x y))
4623+ [(-deref a) (-swap! a f x y)]))
46164624 ([a f x y & more]
4617- (reset-vals! a (apply f (.-state a) x y more))))
4625+ (if (instance? Atom a)
4626+ (reset-vals! a (apply f (.-state a) x y more))
4627+ [(-deref a) (-swap! a f x y more)])))
46184628
46194629(defn compare-and-set!
46204630 " Atomically sets the value of atom to newval if and only if the
0 commit comments