这是Reagent project的摘录。查看complete-all
和clear-done
,我理解重点是更换已修改的地图。我不明白它是如何完成的。 mmap
的定义需要3个参数 - 而complete-all
似乎是用两个调用它,即map
和#(assoc-in % [1 :done] v)
。使用clear-done
和remove
进行#(get-in % [1 :done])
次来电。我尝试使用repl进行实验,但无法让requires
得以解决。
(ns todomvc.core
(:require [reagent.core :as r]))
(defonce todos (r/atom (sorted-map)))
(defonce counter (r/atom 0))
(defn add-todo [text]
(let [id (swap! counter inc)]
(swap! todos assoc id {:id id :title text :done false})))
(defn toggle [id] (swap! todos update-in [id :done] not))
(defn save [id title] (swap! todos assoc-in [id :title] title))
(defn delete [id] (swap! todos dissoc id))
(defn mmap [m f a] (->> m (f a) (into (empty m))))
(defn complete-all [v] (swap! todos mmap map #(assoc-in % [1 :done] v)))
(defn clear-done [] (swap! todos mmap remove #(get-in % [1 :done])))
答案 0 :(得分:-2)
现有地图作为函数的第一个参数传递。当一切都失败了......