Skip to content

Commit e74f757

Browse files
authored
fix(console.log): add custom chrome formatters (#85)
1 parent 04be26b commit e74f757

27 files changed

+2712
-1631
lines changed

.github/workflows/cd.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ jobs:
1313
- uses: actions/setup-node@v1
1414
with:
1515
node-version: '12'
16+
- uses: actions/setup-java@v1
17+
with:
18+
java-version: 1.8
19+
- uses: DeLaGuardo/setup-clojure@3.2
20+
with:
21+
cli: 1.10.1.693
1622
- run: yarn install --frozen-lockfile
1723
- run: yarn test
1824
- run: yarn semantic-release

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ jobs:
1717
with:
1818
node-version: '12'
1919

20+
- uses: actions/setup-java@v1
21+
with:
22+
java-version: 1.8
23+
24+
- uses: DeLaGuardo/setup-clojure@3.2
25+
with:
26+
cli: 1.10.1.693
27+
2028
- name: Get yarn cache directory path
2129
id: yarn-cache-dir-path
2230
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

.github/workflows/publish-examples.yml renamed to .github/workflows/gh-pages.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Publish Examples
22

3-
on:
4-
push:
5-
branches: [ master ]
3+
on: push
64

75
jobs:
86
publish-examples:
@@ -14,6 +12,14 @@ jobs:
1412
- uses: actions/setup-node@v1
1513
with:
1614
node-version: '12'
15+
16+
- uses: actions/setup-java@v1
17+
with:
18+
java-version: 1.8
19+
20+
- uses: DeLaGuardo/setup-clojure@3.2
21+
with:
22+
cli: 1.10.1.693
1723

1824
- name: Get yarn cache directory path
1925
id: yarn-cache-dir-path
@@ -46,9 +52,25 @@ jobs:
4652

4753
- run: yarn shadow-cljs release dev
4854

55+
- name: Extract branch name
56+
shell: bash
57+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
58+
id: extract_branch
59+
4960
- name: Publish to GitHub Pages 🚀
50-
uses: JamesIves/github-pages-deploy-action@releases/v3
61+
uses: JamesIves/github-pages-deploy-action@4.1.0
5162
with:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
BRANCH: gh-pages # The branch the action should deploy to.
54-
FOLDER: public # The folder the action should deploy.
63+
branch: gh-pages
64+
folder: public
65+
target-folder: branches/${{ steps.extract_branch.outputs.branch }}
66+
67+
- name: Slack Notification
68+
uses: rtCamp/action-slack-notify@v2
69+
env:
70+
SLACK_CHANNEL: proj-dev-homebase-react
71+
SLACK_COLOR: ${{ job.status }} # or a specific color like 'green' or '#ff00ff'
72+
SLACK_ICON: https://github.com/homebaseio.png?size=200
73+
SLACK_MESSAGE: "- :github: Branch: <https://github.com/homebaseio/homebase-react/tree/${{ steps.extract_branch.outputs.branch }}|${{ steps.extract_branch.outputs.branch }}>\n- :card_file_box: devcards: https://homebaseio.github.io/homebase-react/branches/${{ steps.extract_branch.outputs.branch }}/index.html"
74+
SLACK_TITLE: "Published ${{ steps.extract_branch.outputs.branch }} to GitHub Pages :rocket:"
75+
SLACK_USERNAME: Homebase
76+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ pom.xml.asc
2929
.hgignore
3030
.hg/
3131
.vscode
32+
.cpcache

README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,42 @@ This hook returns the current database client with some helpful functions for sy
187187

188188
Check out the [Firebase example](https://homebaseio.github.io/homebase-react/#!/example.todo_firebase) for a demonstration of how you might integrate a backend.
189189

190-
## Debugging tips
190+
## Debugging
191+
Homebase React uses ClojureScript and its corresponding data format EDN internally. We then compile all of that to Javascript using the Google Closure Compiler (closure not clojure, I know right) to get as small a bundle as possible. Then we provide APIs (react hooks) that accept JSON and do all the conversion to EDN and back again behind the scenes.
192+
193+
EDN and Clojure provide far more safety and extensibility than JSON and Javascript. Clojure being immutable by default and EDN being extensible. This lets us build and support features that would be unwieldy in JSON and JS.
194+
195+
However, the tradeoffs are:
196+
197+
1. A larger bundle size. Some of the Clojure runtime cannot be compiled away even though the closure compiler is really aggressive.
198+
2. Clojure error messages sometimes leak into JS land. We try to annotate the ones we know about so they make sense to JS devs, but it's far from perfect and if you see something weird please create an issue.
199+
3. Our code is released already minified. We do this because most people do not develop with the google closure compiler and other build tools are not nearly as effective at optimizing this code. This makes debugging homebase-react while developing a bit harder since the code is not very readable, but we think the tradeoff is worth it to provide a smaller bundle size. And to compensate we try to build enough supporting dev tooling so you never need to read the compiled source.
200+
4. Confusing console logs. EDN data looks different from JSON and to add to that, homebase-react mostly outputs entities, which are lazy data types and not very helpful when logged out with the default console formatting. See custom chrome formatters below for a vastly improved logging experience.
201+
202+
### Custom chrome console log formatters
203+
If you develop with [Chrome](https://www.google.com/chrome/) or a Chromium browser like Brave or Edge you'll get significantly more meaningful logs for entities `console.log(anEntity)` due to our use of custom chrome :formatters. These custom formatters allow us to perform lazy database queries to fetch all of an entity's attributes, including references to other entities and all reverse references to the current entity. They let you access your entire data graph from the console, with any logged out entity as an entry point.
204+
205+
**To enable custom chrome formatters**
206+
207+
**1.** Open the preferences panel in chrome devtools by clicking the cog.
208+
209+
<img alt="image of chrome devtools preferences button" src="public/images/enable_chrome_formatters_1.png" width="400">
210+
211+
**2.** Toggle `Enabled custom formatters` on.
212+
213+
<img alt="image of chrome devtools custom formatters toggle" src="public/images/enable_chrome_formatters_2.png" width="400">
214+
215+
**3.** Keep the chrome console open and refresh the page. Any logged out entities should now have the custom formatting.
216+
217+
<img alt="image of custom entity chrome console logs" src="public/images/enable_chrome_formatters_3.png" width="400">
218+
219+
**Live demo:** open the console while on the [todo example](https://homebaseio.github.io/homebase-react/#!/dev.example.todo) page.
220+
221+
**Remember**: for custom formatters to work `console.log(anEntity)` must be called *after* you open the chrome console. Anything logged out before you open the console will not have custom formatting applied because chrome processes those logs in the background.
222+
223+
### *DEPRECATED* `_recentlyTouchedAttributes`
224+
225+
*Use [custom chrome formatters](#custom-chrome-formatters) instead.*
191226

192227
If you set `debug` to `true` in your configuration, you will be able to access the `_recentlyTouchedAttributes` attribute on entities. `_recentlyTouchedAttributes` will show any cached attributes for a given entity. This is helpful for approximating that entity's schema and values.
193228

@@ -199,12 +234,15 @@ If you set `debug` to `true` in your configuration, you will be able to access t
199234

200235
## Roadmap
201236

202-
1. Document integration with more backends
203-
2. Swap [Datascript](https://github.com/tonsky/datascript) out for [Datahike](https://github.com/replikativ/datahike)
237+
1. Improve developer tools: custom chrome formatters, DB admin console extension
238+
2. Rewrite React ↔ Homebase cache
239+
1. Support async DB access (for Datahike)
240+
2. Reactive query planning (better perf on pages with lots of live reads)
241+
3. Swap [Datascript](https://github.com/tonsky/datascript) out for [Datahike](https://github.com/replikativ/datahike)
204242
1. Immutability
205243
2. History / Change Tracking
206-
3. Persist to IndexedDB
207-
4. [Local-first](https://www.inkandswitch.com/local-first.html) conflict resolution for offline caching and sync between multiple devices
244+
4. Persist to IndexedDB
245+
5. [Local-first](https://www.inkandswitch.com/local-first.html) conflict resolution for offline caching and sync between multiple devices
208246

209247
## Limitations
210248
Homebase React is currently not a good choice for read-heavy applications (e.g. Twitter, ecommerce). We plan to support these query patterns with our [platform](http://homebase.io) eventually.

deps.edn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{:paths ["src"]
2+
:deps {thheller/shadow-cljs {:mvn/version "2.11.25"}
3+
devcards/devcards {:mvn/version "0.2.7"}
4+
datascript/datascript {:mvn/version "1.0.7"}
5+
reagent/reagent {:mvn/version "1.0.0-alpha2"}
6+
inflections/inflections {:mvn/version "0.13.2"}
7+
binaryage/devtools {:mvn/version "1.0.2"}
8+
homebaseio/datalog-console {:git/url "https://github.com/homebaseio/datalog-console" :sha "91d5b6009d66807ceec9807a1f8ed099a0a6f219"}
9+
;; homebaseio/datalog-console {:local/root "../datalog-console"}
10+
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.2"}}}

docs/0100|Overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ As data and our need to annotate and organize it grows, so does our need for sup
1414

1515
To solve this problem, modern write-heavy applications such as Superhuman, Roam Research, and Facebook Messenger built their own embedded data layers to enable these more sophisticated user experiences.
1616

17-
Homebase-react enables developers to access the same embedded datalog database as Roam Research through React hooks. You no longer have to build out a team or learn specialized tools like Clojure in order to build a delightful write-heavy application.
17+
Homebase React enables developers to access the same embedded datalog database as Roam Research through React hooks. You no longer have to build out a team or learn specialized tools like Clojure in order to build a delightful write-heavy application.
1818

1919
## Install
2020

docs/0200|Quick_Start.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
> We recommend everyone start by [enabling custom chrome formatters](/docs/homebase-react/main/debugging#custom-chrome-formatters) for a much better debugging experience.
2+
3+
![image of custom entity chrome console logs](https://github.com/homebaseio/homebase-react/blob/master/public/images/enable_chrome_formatters_3.png?raw=true)
4+
5+
Ok. Let's get going.
6+
17
Homebase React creates a local relational database for your React app.
28

9+
Adding `HomebaseProvider` automatically creates the database.
10+
311
```js
412
import { HomebaseProvider } from 'homebase-react'
513

@@ -33,4 +41,8 @@ const App = () => {
3341
</button>
3442
)
3543
}
36-
```
44+
```
45+
46+
For a step by step guide take a look at the [tutorial](/docs/homebase-react/main/tutorial).
47+
48+
Check out the [API docs](/docs/homebase-react/main/api) to learn about our other hooks like [`useQuery`](/docs/homebase-react/main/api#usequery) and [`useClient`](/docs/homebase-react/main/api#useclient).

docs/0300|Tutorial.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
This tutorial takes you through our [Todo Example](https://homebaseio.github.io/homebase-react/#!/example.todo).
22

3+
## Custom chrome formatters
4+
5+
> We recommend everyone start by [enabling custom chrome formatters](/docs/homebase-react/main/debugging#custom-chrome-formatters) for a much better debugging experience.
6+
7+
![image of custom entity chrome console logs](https://github.com/homebaseio/homebase-react/blob/master/public/images/enable_chrome_formatters_3.png?raw=true)
8+
39
## HomebaseProvider
410

5-
Let's get started.
11+
Welcome back. Let's get started for real.
612

713
`HomebaseProvider` is a component that wraps your React app and creates a local relational database. This database is then accessible to any child components via React Hooks.
814

docs/0400|API.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
> We recommend everyone start by [enabling custom chrome formatters](/docs/homebase-react/main/debugging#custom-chrome-formatters) for a much better debugging experience.
2+
3+
![image of custom entity chrome console logs](https://github.com/homebaseio/homebase-react/blob/master/public/images/enable_chrome_formatters_3.png?raw=true)
4+
15
## `HomebaseProvider`
26

37
The HomebaseProvider wraps your React app and makes a relational database accessible to all of your components. Configure it with `lookupHelpers` and `initialData`.

0 commit comments

Comments
 (0)