Skip to content

Instantly share code, notes, and snippets.

@divs1210
Created December 14, 2018 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divs1210/b00cee39fb1f5f0ab210b7ec6d193902 to your computer and use it in GitHub Desktop.
Save divs1210/b00cee39fb1f5f0ab210b7ec6d193902 to your computer and use it in GitHub Desktop.
Lightweight logging of db state changes for reagent/re-frame
(defn watch-db []
(add-watch re-frame.db/app-db :watcher
(fn [_ _ old-state new-state]
(let [[removed added] (clojure.data/diff old-state new-state)]
(when (or removed added)
(println "=====\nRemoved:")
(cljs.pprint/pprint removed)
(println "Added:")
(cljs.pprint/pprint added))))))
(defn unwatch-db []
(remove-watch re-frame.db/app-db :watcher))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment