Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Oct 11, 2024
1 parent b315541 commit 6997496
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ tmp
playground/public/public/src/squint
!playground/viteconfig.mjs
out
.env
2 changes: 2 additions & 0 deletions examples/instant/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
main.jsx
19 changes: 19 additions & 0 deletions examples/instant/debug.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { init, tx, id } from '@instantdb/core';
var APP_ID=process.env.VITE_APP_ID;
var db = init(({ "appId": APP_ID }));
var add_name = function (n) {
const v1 = (db.transact(tx.names[id()].update({name: 'dude'})));
return console.log("v", v1);
};

add_name("hello");
db.subscribeQuery({ names: {} }, (resp) => {
if (resp.error) {
console.log('error');
renderError(resp.error.message); // Pro-tip: Check you have the right appId!
return;
}
if (resp.data) {
render(resp.data);
}
});
6 changes: 6 additions & 0 deletions examples/instant/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<head>
<script type="module" src="main.jsx"></script>
</head>
<body>
<div id="app"/>
</body>
41 changes: 41 additions & 0 deletions examples/instant/main.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(ns main
(:require ["@instantdb/react" :refer [init tx id]]
["react-dom/client" :as rdom]
["react" :as React]))

(def APP_ID js/import.meta.env.VITE_APP_ID)

(def db (init {:appId APP_ID}))

(defn ^:async add-name [n]
(let [v (js-await
(.transact db
(-> tx.names (aget (id))
(.update {:name n
:createdAt (js/Date.now)}))))]
(js/console.log :v v)))

(defn Names [data]
(let [names data.names]
#jsx [:<>
(map (fn [n]
#jsx [:div "Name: " n])
names)]))

(defn App []
(let [[isLoading error data] (.useQuery db {:names {}})]
#jsx [:div
[:p "Add name"]
[:form
{:onSubmit (fn [e]
(.preventDefault e)
(let [n (-> e .-target first)]
(add-name n.value)
(set! n.value "")))}
[:input]]
(js/console.log data)
[:div [Names data]]]))

(def root (rdom/createRoot (js/document.getElementById "app")))
(.render root #jsx [App])
1
11 changes: 11 additions & 0 deletions examples/instant/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"@instantdb/react": "^0.14.15",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"squint-cljs": "^0.8.117"
},
"devDependencies": {
"vite": "^5.4.8"
}
}
1 change: 1 addition & 0 deletions examples/instant/squint.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["."]}

0 comments on commit 6997496

Please sign in to comment.