|
7 | 7 | list,
|
8 | 8 | id,
|
9 | 9 | type Todo,
|
10 |
| - } from '../lib/stores' |
| 10 | + } from '../lib/stores.svelte' |
11 | 11 |
|
12 | 12 | const queryClient = useQueryClient()
|
13 | 13 |
|
14 |
| - let name = '' |
| 14 | + let name = $state('') |
15 | 15 |
|
16 | 16 | const postTodo = async ({ name, notes }: Omit<Todo, 'id'>) => {
|
17 | 17 | console.info('postTodo', { name, notes })
|
18 | 18 | return new Promise((resolve, reject) => {
|
19 | 19 | setTimeout(
|
20 | 20 | () => {
|
21 |
| - if (Math.random() < $errorRate) { |
| 21 | + if (Math.random() < errorRate.value) { |
22 | 22 | return reject(
|
23 | 23 | new Error(JSON.stringify({ postTodo: { name, notes } }, null, 2)),
|
24 | 24 | )
|
25 | 25 | }
|
26 |
| - const todo = { name, notes, id: $id } |
27 |
| - id.set($id + 1) |
28 |
| - list.set([...$list, todo]) |
| 26 | + const todo = { name, notes, id: id.value } |
| 27 | + id.value = id.value + 1 |
| 28 | + list.value = [...list.value, todo] |
29 | 29 | resolve(todo)
|
30 | 30 | },
|
31 |
| - $queryTimeMin + Math.random() * ($queryTimeMax - $queryTimeMin), |
| 31 | + queryTimeMin.value + |
| 32 | + Math.random() * (queryTimeMax.value - queryTimeMin.value), |
32 | 33 | )
|
33 | 34 | })
|
34 | 35 | }
|
|
42 | 43 | </script>
|
43 | 44 |
|
44 | 45 | <div>
|
45 |
| - <input bind:value={name} disabled={$addMutation.status === 'pending'} /> |
| 46 | + <input bind:value={name} disabled={addMutation.status === 'pending'} /> |
46 | 47 |
|
47 | 48 | <button
|
48 |
| - onclick={() => $addMutation.mutate({ name, notes: name })} |
49 |
| - disabled={$addMutation.status === 'pending' || !name} |
| 49 | + onclick={() => addMutation.mutate({ name, notes: name })} |
| 50 | + disabled={addMutation.status === 'pending' || !name} |
50 | 51 | >
|
51 | 52 | Add Todo
|
52 | 53 | </button>
|
53 | 54 |
|
54 | 55 | <div>
|
55 |
| - {$addMutation.status === 'pending' |
| 56 | + {addMutation.status === 'pending' |
56 | 57 | ? 'Saving...'
|
57 |
| - : $addMutation.status === 'error' |
58 |
| - ? $addMutation.error.message |
| 58 | + : addMutation.status === 'error' |
| 59 | + ? addMutation.error.message |
59 | 60 | : 'Saved!'}
|
60 | 61 | </div>
|
61 | 62 | </div>
|
0 commit comments