set-validator!

functionsince v0.0-927 clojure.core/set-validator!Edit
(set-validator! iref val)

Details:

Sets a validator function for atom a.

fn must be nil or a side-effect-free function of one argument, which will be passed the intended new state on any state change. fn should return false or throw an Error if the new state is unacceptable.

If the current value of a is unacceptable to fn when set-validator! is called, an Error will be thrown and the validator will not be set.

(set-validator! my-atom nil) will remove the validator from my-atom.


See Also:


Source docstring:
Sets the validator-fn for an atom. validator-fn must be nil or a
side-effect-free fn of one argument, which will be passed the intended
new state on any state change. If the new state is unacceptable, the
validator-fn should return false or throw an Error. If the current state
is not acceptable to the new validator, an Error will be thrown and the
validator will not be changed.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn set-validator!
  [iref val]
  (when (and (some? val)
             (not (val (-deref iref))))
    (throw (js/Error. "Validator rejected reference state")))
  (set! (.-validator iref) val))