Skip to content

Commit

Permalink
feat(datalog-console): respond to datalog-console messages (#91)
Browse files Browse the repository at this point in the history

Co-authored-by: Chris Smothers <chris.smothers@gmail.com>
  • Loading branch information
groundedsage and becomingbabyman committed May 13, 2021
1 parent c17ec93 commit e5584da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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)

(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

4 comments on commit e5584da

@vercel
Copy link

@vercel vercel bot commented on e5584da May 13, 2021

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

homebase-example-todo – ./examples/todo

homebase-example-todo.vercel.app
homebase-example-todo-homebaseio.vercel.app
homebase-example-todo-git-master-homebaseio.vercel.app

@vercel
Copy link

@vercel vercel bot commented on e5584da May 13, 2021

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on e5584da May 13, 2021

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on e5584da May 13, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.