-
Notifications
You must be signed in to change notification settings - Fork 10
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
Upload to NPM? #29
Comments
We're working on it. At the moment the datalog-console is designed to be used in the chrome extension almost exclusively. You can also grab it off clojars if you're using Clojurescript, but we haven't exposed all the requisite APIs to make it work outside of the chrome extension. Are you just trying to connect it to a datascript DB? |
yeah, from the js api. I'm planning to use it with chrome so that's a non-issue. (datalog-console/enable! {:conn conn}) from js (so far as I know...) |
So I was able to make it work but...
:npm {:target :esm
:output-dir "dist/js"
:modules {:datalog-console {:exports {enable datalog-console.integrations.datascript/enable-js}}}}
// from js
enable(() => datascript.serializable(datascript.db(conn)));
(ns datalog-console.integrations.datascript
(:require [goog.object :as gobj]
[cljs.reader]
[datascript.core :as d]
[datalog-console.lib.version :as dc]
[datascript.serialize :as ds]))
(defn- thaw-fn [s]
(-> (cljs.reader/read-string s)
(clj->js)
(js->clj :keywordize-keys true)))
(defn get-db [conn-fn]
(-> (conn-fn)
(ds/from-serializable {:thaw-fn thaw-fn :thaw-kw keyword})))
(defn transact-from-devtool! [conn transact-str]
(try
(d/transact conn (cljs.reader/read-string transact-str))
{:datalog-console.client.response/transact! :success}
(catch js/Error e {:error (goog.object/get e "message")})))
(defn enable!
"Takes a [datascript](https://github.com/tonsky/datascript) database connection atom. Adds message handlers for a remote datalog-console process to communicate with. E.g. the datalog-console browser [extension](https://chrome.google.com/webstore/detail/datalog-console/cfgbajnnabfanfdkhpdhndegpmepnlmb?hl=en)."
[{:keys [conn]}]
(try
(js/document.documentElement.setAttribute "__datalog-console-remote-installed__" true)
(.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 (get-db conn))} "*")
:datalog-console.client/transact!
(let [transact-result (transact-from-devtool! conn (:data (cljs.reader/read-string devtool-message)))]
(.postMessage js/window #js {":datalog-console.remote/remote-message" (pr-str transact-result)} "*"))
:datalog-console.client/request-integration-version
(.postMessage js/window #js {":datalog-console.remote/remote-message" (pr-str {:version dc/version})})
nil)))))
(catch js/Error _e nil)))
(defn ^:export enable-js [conn]
(enable! {:conn conn})) And finally I could go to the chrome extension and load my db :)! |
I would like to use this tool from js (without homebase) but I can't seem to find it on npm.
Is there an easy way of integration from js (without homebase) that I'm missing?
The text was updated successfully, but these errors were encountered: