clojurescript 试剂交换!原子否定原子值

标签 clojurescript reagent

我试图反转试剂原子的值变化

(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/

相关文章:

clojure - 如何将字符串解析为 Hiccup?

clojurescript - 无法在 OM 中显示两个组件

regex - 使用 IFn 扩展 Clojure 正则表达式以支持映射

clojurescript - 试剂组件未更新

clojurescript - 试剂 react Clojurescript 警告 : Every element in a seq should have a unique :key

javascript - 在服务器和浏览器上使用 Macchiato 框架的 CIDER

android - 如何设置 Shadow-cljs 以使用 Cordova + Clojurescript 重新加载代码?

html - 在 Reagent 中使用 HTML 模板(作为文件)

clojurescript - 在试剂的 :reagent-render function 中获取 Prop

clojure - Re-frame 中的 reg-event-db、reg-event-fx 和 reg-event-ctx 有什么区别?