re-frame-10x/docs/HyperlinkedInformation/Diffs.md

28 lines
1.4 KiB
Markdown
Raw Normal View History

2018-01-17 12:25:41 +00:00
This document briefly explains what you are seeing in those mysterious sections
labelled "Only Before" and "Only After". Enlightenment is nigh.
2018-01-18 01:23:12 +00:00
`re-frame-trace` allows you to inspect important values like `app-db`.
While knowing current values is useful,
you are often more interested to know how a value has changed.
The value might start off as, say, `X` (before the event happened) but
2018-01-18 00:50:18 +00:00
ended up as `X'`. How are `X` and `X'` different, you wonder?
2018-01-17 12:25:41 +00:00
What got added or removed? What was modified?
2018-01-18 01:23:12 +00:00
So, how then to display changes in a way that's easy to understand? I'm glad you asked.
2018-01-18 00:50:18 +00:00
`re-frame-trace` chooses to do a calculation best shown by this pseudo code:
```clj
(let [[only-before only-after _] (clojure.data/diff X X')]
...)
```
2018-01-18 01:23:12 +00:00
Remember X is the value immediately `before` (this epoch). And `X'` is the value `after` (the epoch has completed).
2018-01-17 12:25:41 +00:00
By [looking at the docs](https://clojuredocs.org/clojure.data/diff) on `diff`, you'll see
2018-01-18 01:31:14 +00:00
that it calculates how two values differ, and returns a triple of values. `re-frame-trace`
captures and displays the first two elements of this triple as "only before" and "only after"
respectively. The 3rd element is ignored because it is not very interesting - it says
what hasn't changed, so it isn't shown.
2018-01-17 12:25:41 +00:00
2018-01-18 01:31:14 +00:00
To correctly interpret "Only Before" and "Only after", you'll need to spend a bit
2018-01-17 12:25:41 +00:00
of time properly familiarising yourself with how `clojure.data/diff` works, but
2018-01-18 01:23:12 +00:00
it will be a worthwhile time investment.