Skip to content

feat(datalog-console): add datalog-console #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/homebase/datalog_console.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns homebase.datalog-console
(:require [goog.object :as gobj]
[cljs.reader]))

(js/document.documentElement.setAttribute "__datalog-console-remote-installed__" true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groundedsage it looks like this breaks Next.js support for HBR with the following error:

error - ReferenceError: document is not defined
    at /Users/jb/repos/supabase-js/example/next-todo/node_modules/homebase-react/dist/js/homebase.react.js:1491:479
    at /Users/jb/repos/supabase-js/example/next-todo/node_modules/homebase-react/dist/js/homebase.react.js:6:22
    at Object.<anonymous> (/Users/jb/repos/supabase-js/example/next-todo/node_modules/homebase-react/dist/js/homebase.react.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at eval (webpack-internal:///homebase-react:1:18)
Installing CLJS DevTools 1.0.2 and enabling features :formatters :hints :async
ReferenceError: document is not defined
    at /Users/jb/repos/supabase-js/example/next-todo/node_modules/homebase-react/dist/js/homebase.react.js:1491:479
    at /Users/jb/repos/supabase-js/example/next-todo/node_modules/homebase-react/dist/js/homebase.react.js:6:22
    at Object.<anonymous> (/Users/jb/repos/supabase-js/example/next-todo/node_modules/homebase-react/dist/js/homebase.react.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at eval (webpack-internal:///homebase-react:1:18)
CLJS DevTools: some custom formatters were not rendered.
https://github.com/binaryage/cljs-devtools/blob/master/docs/faq.md#why-some-custom-formatters-were-not-rendered
CLJS DevTools: some custom formatters were not rendered.
https://github.com/binaryage/cljs-devtools/blob/master/docs/faq.md#why-some-custom-formatters-were-not-rendered

Can you please do error catching here and make it a warning when it fails vs breaking compilation?


(defn init!
[{:keys [conn]}]
(.addEventListener js/window "message"
(fn [event]
(when-let [devtool-message (gobj/getValueByKeys event "data" ":datalog-console.client/devtool-message")]
(let [msg-type (:type (cljs.reader/read-string devtool-message))]
(case msg-type

:datalog-console.client/request-whole-database-as-string
(.postMessage js/window #js {":datalog-console.remote/remote-message" (pr-str @conn)} "*")

nil))))))
6 changes: 5 additions & 1 deletion src/homebase/react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
[clojure.set]
[homebase.js :as hbjs]
[datascript.core :as d]
[datascript.impl.entity :as de]))
[datascript.impl.entity :as de]
[homebase.datalog-console :as datalog-console]))



(defn try-hook [hook-name f]
(if hbjs/*debug*
Expand Down Expand Up @@ -134,6 +137,7 @@
conn (d/create-conn (if schema
(merge (hbjs/js->schema schema) base-schema)
base-schema))]
(datalog-console/init! {:conn conn})
(when initial-tx (hbjs/transact! conn initial-tx))
(react/createElement
(goog.object/get homebase-context "Provider")
Expand Down