Skip to content

Commit eb96cc8

Browse files
Take two on inputs (#19)
* works fine locally, breaks in prod * better approach * Better
1 parent 92f7a72 commit eb96cc8

File tree

7 files changed

+159
-196
lines changed

7 files changed

+159
-196
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
pnpm-lock.yaml
33
package-lock.json
44
yarn.lock
5+
src/convex/_generated/

convex.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"functions": "src/convex/"
2+
"functions": "src/convex/"
33
}

src/convex/README.md

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,66 @@ A query function that takes two arguments looks like:
77

88
```ts
99
// functions.js
10-
import { query } from "./_generated/server";
11-
import { v } from "convex/values";
10+
import { query } from './_generated/server';
11+
import { v } from 'convex/values';
1212

1313
export const myQueryFunction = query({
14-
// Validators for arguments.
15-
args: {
16-
first: v.number(),
17-
second: v.string(),
18-
},
19-
20-
// Function implementation.
21-
handler: async (ctx, args) => {
22-
// Read the database as many times as you need here.
23-
// See https://docs.convex.dev/database/reading-data.
24-
const documents = await ctx.db.query("tablename").collect();
25-
26-
// Arguments passed from the client are properties of the args object.
27-
console.log(args.first, args.second);
28-
29-
// Write arbitrary JavaScript here: filter, aggregate, build derived data,
30-
// remove non-public properties, or create new objects.
31-
return documents;
32-
},
14+
// Validators for arguments.
15+
args: {
16+
first: v.number(),
17+
second: v.string()
18+
},
19+
20+
// Function implementation.
21+
handler: async (ctx, args) => {
22+
// Read the database as many times as you need here.
23+
// See https://docs.convex.dev/database/reading-data.
24+
const documents = await ctx.db.query('tablename').collect();
25+
26+
// Arguments passed from the client are properties of the args object.
27+
console.log(args.first, args.second);
28+
29+
// Write arbitrary JavaScript here: filter, aggregate, build derived data,
30+
// remove non-public properties, or create new objects.
31+
return documents;
32+
}
3333
});
3434
```
3535

3636
Using this query function in a React component looks like:
3737

3838
```ts
3939
const data = useQuery(api.functions.myQueryFunction, {
40-
first: 10,
41-
second: "hello",
40+
first: 10,
41+
second: 'hello'
4242
});
4343
```
4444

4545
A mutation function looks like:
4646

4747
```ts
4848
// functions.js
49-
import { mutation } from "./_generated/server";
50-
import { v } from "convex/values";
49+
import { mutation } from './_generated/server';
50+
import { v } from 'convex/values';
5151

5252
export const myMutationFunction = mutation({
53-
// Validators for arguments.
54-
args: {
55-
first: v.string(),
56-
second: v.string(),
57-
},
58-
59-
// Function implementation.
60-
handler: async (ctx, args) => {
61-
// Insert or modify documents in the database here.
62-
// Mutations can also read from the database like queries.
63-
// See https://docs.convex.dev/database/writing-data.
64-
const message = { body: args.first, author: args.second };
65-
const id = await ctx.db.insert("messages", message);
66-
67-
// Optionally, return a value from your mutation.
68-
return await ctx.db.get(id);
69-
},
53+
// Validators for arguments.
54+
args: {
55+
first: v.string(),
56+
second: v.string()
57+
},
58+
59+
// Function implementation.
60+
handler: async (ctx, args) => {
61+
// Insert or modify documents in the database here.
62+
// Mutations can also read from the database like queries.
63+
// See https://docs.convex.dev/database/writing-data.
64+
const message = { body: args.first, author: args.second };
65+
const id = await ctx.db.insert('messages', message);
66+
67+
// Optionally, return a value from your mutation.
68+
return await ctx.db.get(id);
69+
}
7070
});
7171
```
7272

@@ -75,13 +75,11 @@ Using this mutation function in a React component looks like:
7575
```ts
7676
const mutation = useMutation(api.functions.myMutationFunction);
7777
function handleButtonPress() {
78-
// fire and forget, the most common way to use mutations
79-
mutation({ first: "Hello!", second: "me" });
80-
// OR
81-
// use the result once the mutation has completed
82-
mutation({ first: "Hello!", second: "me" }).then((result) =>
83-
console.log(result)
84-
);
78+
// fire and forget, the most common way to use mutations
79+
mutation({ first: 'Hello!', second: 'me' });
80+
// OR
81+
// use the result once the mutation has completed
82+
mutation({ first: 'Hello!', second: 'me' }).then((result) => console.log(result));
8583
}
8684
```
8785

src/convex/seed_messages.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
export default [
2-
{
3-
_creationTime: 1691013604325.0217,
4-
_id: "2w1tjesf0ng55yvwzv5gkehv9hsy20r",
5-
author: "Tom",
6-
body: "Let's talk about vim vs VS Code!",
7-
},
8-
{
9-
_creationTime: 1691013604325.0137,
10-
_id: "2w4w1wx9f0bpgm1adt0w6j689hspwq8",
11-
author: "Sujay",
12-
body: "What about emacs?",
13-
},
2+
{
3+
_creationTime: 1691013604325.0217,
4+
_id: '2w1tjesf0ng55yvwzv5gkehv9hsy20r',
5+
author: 'Tom',
6+
body: "Let's talk about vim vs VS Code!"
7+
},
8+
{
9+
_creationTime: 1691013604325.0137,
10+
_id: '2w4w1wx9f0bpgm1adt0w6j689hspwq8',
11+
author: 'Sujay',
12+
body: 'What about emacs?'
13+
},
1414

15-
{
16-
_creationTime: 1691013604325.0095,
17-
_id: "2w6q24ygyjhsb0mxq619y8v09hsxyeg",
18-
author: "Tom",
19-
body: "I spend so much time customizing my vim config, and now I need to learn Lua to configure neovim!",
20-
},
21-
{
22-
_creationTime: 1691013604325.0125,
23-
_id: "2w7c8t54p3be7gd212vhnabw9hsqwdr",
24-
author: "James",
25-
body: "I use the defaults settings for everything.",
26-
},
27-
{
28-
_creationTime: 1691013604325.0205,
29-
_id: "2w7d7p8ysmtr6njf4yejj0jy9hsjar0",
30-
author: "Arnold",
31-
body: "While you were talking I added a feature to the product",
32-
},
15+
{
16+
_creationTime: 1691013604325.0095,
17+
_id: '2w6q24ygyjhsb0mxq619y8v09hsxyeg',
18+
author: 'Tom',
19+
body: 'I spend so much time customizing my vim config, and now I need to learn Lua to configure neovim!'
20+
},
21+
{
22+
_creationTime: 1691013604325.0125,
23+
_id: '2w7c8t54p3be7gd212vhnabw9hsqwdr',
24+
author: 'James',
25+
body: 'I use the defaults settings for everything.'
26+
},
27+
{
28+
_creationTime: 1691013604325.0205,
29+
_id: '2w7d7p8ysmtr6njf4yejj0jy9hsjar0',
30+
author: 'Arnold',
31+
body: 'While you were talking I added a feature to the product'
32+
}
3333
];

src/convex/tsconfig.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
/* This TypeScript project config describes the environment that
3-
* Convex functions run in and is used to typecheck them.
4-
* You can modify it, but some settings required to use Convex.
5-
*/
6-
"compilerOptions": {
7-
/* These settings are not required by Convex and can be modified. */
8-
"allowJs": true,
9-
"strict": true,
2+
/* This TypeScript project config describes the environment that
3+
* Convex functions run in and is used to typecheck them.
4+
* You can modify it, but some settings required to use Convex.
5+
*/
6+
"compilerOptions": {
7+
/* These settings are not required by Convex and can be modified. */
8+
"allowJs": true,
9+
"strict": true,
1010

11-
/* These compiler options are required by Convex */
12-
"target": "ESNext",
13-
"lib": ["ES2021", "dom"],
14-
"forceConsistentCasingInFileNames": true,
15-
"allowSyntheticDefaultImports": true,
16-
"module": "ESNext",
17-
"moduleResolution": "Node",
18-
"isolatedModules": true,
19-
"skipLibCheck": true,
20-
"noEmit": true
21-
},
22-
"include": ["./**/*"],
23-
"exclude": ["./_generated"]
11+
/* These compiler options are required by Convex */
12+
"target": "ESNext",
13+
"lib": ["ES2021", "dom"],
14+
"forceConsistentCasingInFileNames": true,
15+
"allowSyntheticDefaultImports": true,
16+
"module": "ESNext",
17+
"moduleResolution": "Node",
18+
"isolatedModules": true,
19+
"skipLibCheck": true,
20+
"noEmit": true
21+
},
22+
"include": ["./**/*"],
23+
"exclude": ["./_generated"]
2424
}

src/routes/inputs/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<h1>Modifying several inputs</h1>
1212
<p>Any user have complete control over these inputs but might change them quickly.</p>
1313

14-
<Inputs/>
14+
<Inputs />
1515
</section>
1616

1717
<style>

0 commit comments

Comments
 (0)