-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ tmp | |
playground/public/public/src/squint | ||
!playground/viteconfig.mjs | ||
out | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
main.jsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:paths ["."]} |