我试图反转试剂原子的值变化
(def changeval(reagent/atom 0))
...
...
[:input {:type "button" :value "Invert!"
:on-click #(swap! changeval(not= changeval0 ) ) }]
没有任何反应,我怎样才能使 changeval = NOT(changeval)
最佳答案
检查 swap!
的签名功能:
(swap! atom f)
(swap! atom f x)
(swap! atom f x y)
(swap! atom f x y & args)
Atomically swaps the value of atom to be:
(apply f current-value-of-atom args)
. Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in.
因此要否定原子中的值(它与 Clojure 和 Reagent 的原子一样工作)使用 not
函数(在您的情况下,不会有额外的参数,因为您将只使用原子的当前值):
(def value (atom true))
(swap! value not)
;; => false
(swap! value not)
;; => true
关于clojurescript 试剂交换!原子否定原子值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43054993/