; Clojure 没有事件;atom 上的监视器会通知每一次变化
(def statistic (atom {:starts-count 0 :last-game ""}))
(def started-game (atom nil))
; 订阅变化
(add-watch started-game :statistic
(fn [_key _ref _old name]
(swap! statistic #(-> %
(update :starts-count inc)
(assoc :last-game name)))))
(reset! started-game "Doom")
(reset! started-game "Heroes")
; last-game is "Heroes"
; starts-count is 2
(println "lastGame is" (:last-game @statistic))
(println "startsCount is" (:starts-count @statistic))