1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { init, tx, id } from 'npm:@instantdb/admin';
// ID for app: wonderful-wombat
const INSTANT_APP_ID = '39d1e341-f09a-4e77-8d5b-d368f65531b2';
const INSTANT_ADMIN_TOKEN = '86de53ab-eddb-4349-aed1-0665e55a74c0';
const db = init({
appId: INSTANT_APP_ID,
adminToken: INSTANT_ADMIN_TOKEN,
})
db?.transact(
tx?.messages?.[id()]?.update({
text: "banana!"
})
);
// // db.subscribeQuery({ todos: {} }, (resp) => {
// // if (resp.error) {
// // renderError(resp.error.message); // Pro-tip: Check you have the right appId!
// // return;
// // }
// // if (resp.data) {
// // render(resp.data);
// // }
// // });
// // Write Data
// // ---------
// function addTodo(text) {
// db.transact([tx.messages[id()].update({ text: 'what' })]);
// // db.transact(
// // tx.messages[id()].update({
// // text,
// // done: false,
// // createdAt: Date.now(),
// // })
// // );
// }
// function deleteTodoItem(message) {
// db.transact(tx.messages[message.id].delete());
// }
// function toggleDone(message) {
// db.transact(tx.messages[message.id].update({ done: !message.done }));
// }
// function deleteCompleted(messages) {
// const completed = messages.filter((message) => message.done);
// const txs = completed.map((message) => tx.messages[message.id].delete());
// db.transact(txs);
// }
// function toggleAllTodos(messages) {
// const newVal = !messages.every((message) => message.done);
// db.transact(messages.map((message) => tx.messages[message.id].update({ done: newVal })));
// }
// function query(q = { messages: {} }) {
// const { isLoading, error, data } = db.subscribeQuery({ messages: {} });
// console.log('data', data);
// }
// function renderError(error) {
// console.error(error);
// }
// function render(data) {
// console.log(data);
// }
// addTodo("hello!")
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 23, 2024