@@ -4569,15 +4569,17 @@ reduces them without incurring seq initialization"
4569
4569
atom before and after the reset."
4570
4570
{:added " 1.9" }
4571
4571
[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)]))
4581
4583
4582
4584
(defn swap!
4583
4585
" Atomically swaps the value of atom to be:
@@ -4608,13 +4610,21 @@ reduces them without incurring seq initialization"
4608
4610
Returns [old new], the value of the atom before and after the swap."
4609
4611
{:added " 1.9" }
4610
4612
([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)]))
4612
4616
([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)]))
4614
4620
([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)]))
4616
4624
([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)])))
4618
4628
4619
4629
(defn compare-and-set!
4620
4630
" Atomically sets the value of atom to newval if and only if the
0 commit comments