2016-08-29 23:06:41 +10:00
|
|
|
### Question
|
2016-08-29 22:57:35 +10:00
|
|
|
|
|
|
|
How can I inspect the contents of `app-db`? Perhaps from figwheel.
|
|
|
|
|
2016-08-29 23:06:41 +10:00
|
|
|
### Short Answer
|
2016-08-29 22:57:35 +10:00
|
|
|
|
|
|
|
If at a REPL, inspect: `re-frame.db/app-db`.
|
|
|
|
|
|
|
|
If at the js console, that's `window.re_frame.db.app_db.state`.
|
|
|
|
|
2017-01-16 13:22:48 -07:00
|
|
|
You are [using cljs-devtools](https://github.com/binaryage/cljs-devtools), right?
|
2016-08-29 22:57:35 +10:00
|
|
|
If not, stop everything and immediately make that happen.
|
|
|
|
|
2016-08-29 23:06:41 +10:00
|
|
|
### Better Answer
|
2016-08-29 22:57:35 +10:00
|
|
|
|
2016-09-05 20:37:00 +10:00
|
|
|
Are you sure you need to?
|
2016-08-29 22:57:35 +10:00
|
|
|
|
|
|
|
First, you seldom want to inspect all of `app-db`.
|
2016-12-22 22:48:41 +11:00
|
|
|
And, second, inspecting via a REPL might be clumsy.
|
2016-08-29 22:57:35 +10:00
|
|
|
|
2016-09-05 20:37:00 +10:00
|
|
|
Instead, you probably want to inspect a part of `app-db`. __And__ you probably want
|
|
|
|
to inspect it directly in the GUI itself, not off in a REPL.
|
2016-08-29 22:57:35 +10:00
|
|
|
|
|
|
|
Here is a useful technique from @escherize. Add something like this to
|
|
|
|
the hiccup of your view ...
|
|
|
|
```clj
|
|
|
|
[:pre (with-out-str (pprint @interesting))]
|
|
|
|
```
|
2016-09-05 20:37:00 +10:00
|
|
|
This assumes that `@interesting` is the value (ratom or subscription)
|
|
|
|
you want to observe (note the @ in front).
|
2016-08-29 22:57:35 +10:00
|
|
|
|
|
|
|
`pprint` output is nice to read, but not compact. For a more compact view, do this:
|
|
|
|
```clj
|
2016-09-05 20:37:00 +10:00
|
|
|
[:pre (pr-str @some-atom)] ;; NB: using pr-str instead of pprint
|
2016-08-29 22:57:35 +10:00
|
|
|
```
|
|
|
|
|
2016-09-05 20:37:00 +10:00
|
|
|
If you choose to use `pprint` then you'll need to `require` it within the `ns` of your `view.cljs`:
|
2016-08-29 22:57:35 +10:00
|
|
|
```clj
|
|
|
|
[cljs.pprint :refer [pprint]]
|
|
|
|
```
|
|
|
|
|
|
|
|
Finally, combining the short and long answers, you could even do this:
|
|
|
|
```clj
|
|
|
|
[:pre (with-out-str (pprint @re-frame.db/app-db))] ;; see everything!
|
|
|
|
```
|
|
|
|
or
|
|
|
|
```clj
|
|
|
|
[:pre (with-out-str (pprint (:part @re-frame.db/app-db)))] ;; see a part of it!
|
|
|
|
```
|
|
|
|
|
|
|
|
You definitely have [clj-devtools](https://github.com/binaryage/cljs-devtools) installed now, right?
|
|
|
|
|
2016-09-05 20:37:00 +10:00
|
|
|
### Other Inspection Tools
|
|
|
|
|
2016-12-22 22:48:41 +11:00
|
|
|
Another very strong tool is [re-Frisk](https://github.com/flexsurfer/re-frisk) which
|
|
|
|
provides a nice solution for navigating and inspecting your re-frame data structures.
|
|
|
|
|
2016-09-05 20:37:00 +10:00
|
|
|
@yogthos' [json-html library](https://github.com/yogthos/json-html) provides
|
|
|
|
a slick presentation, at the expense of more screen real estate, and the
|
|
|
|
need to include specific CSS.
|
|
|
|
|
2016-11-07 09:12:24 +13:00
|
|
|
***
|
|
|
|
|
2016-08-29 22:57:35 +10:00
|
|
|
Up: [FAQ Index](README.md)
|
2016-12-18 23:42:45 +11:00
|
|
|
|
|
|
|
|
|
|
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
|
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
|
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|