middleware/debug: Log a single line if app-db not changed by a handler

middleware/debug logs a group to the console even if there has been no
change to app-db. This makes it harder to tell if you've made a mistake
in refactoring, as the same log message will be shown whether or not
app-db is changing.

This change will log a single line if app-db is not changed by a handler

Fixes #166
This commit is contained in:
Daniel Compton 2016-05-05 11:56:09 +12:00
parent be6c53131d
commit c085ac8bb0
2 changed files with 37 additions and 29 deletions

View File

@ -1,3 +1,8 @@
## Unreleased
Improvements
- `debug` middleware logs a single log line instead of a group if there is no difference in app-db between before and after running the handler.
## 0.7.0 (2016-03-14) ## 0.7.0 (2016-03-14)
Breaking: Breaking:

View File

@ -47,11 +47,14 @@
[db v] [db v]
(log "Handling re-frame event: " v) (log "Handling re-frame event: " v)
(let [new-db (handler db v) (let [new-db (handler db v)
diff (data/diff db new-db)] [before after] (data/diff db new-db)
(group "clojure.data/diff for: " v) db-changed? (or (some? before) (some? after))]
(log "only before: " (first diff)) (if db-changed?
(log "only after : " (second diff)) (do (group "clojure.data/diff for: " v
(groupEnd) (log "only before: " before)
(log "only after : " after))
(groupEnd))
(log "clojure.data/diff no changes for: " v))
new-db))) new-db)))