diff --git a/src/simple-todos/step02/imports/ui/App.svelte b/src/simple-todos/step02/imports/ui/App.svelte
index 3f1b70f..aa9e1a3 100644
--- a/src/simple-todos/step02/imports/ui/App.svelte
+++ b/src/simple-todos/step02/imports/ui/App.svelte
@@ -2,18 +2,25 @@
import Task from './Task.svelte';
import { TasksCollection } from '../api/TasksCollection';
- $m: tasks = TasksCollection.find({}).fetch()
+ let getTasks;
+ $m: getTasks = TasksCollection.find({}).fetchAsync()
-
- {#each tasks as task (task._id)}
-
- {/each}
-
+ {#await getTasks}
+
Loading...
+ {:then tasks}
+
+ {#each tasks as task (task._id)}
+
+ {/each}
+
+ {:catch error}
+
{error.message}
+ {/await}
diff --git a/src/simple-todos/step02/server/main.js b/src/simple-todos/step02/server/main.js
index cd5ce50..896720a 100644
--- a/src/simple-todos/step02/server/main.js
+++ b/src/simple-todos/step02/server/main.js
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TasksCollection';
-const insertTask = taskText => TasksCollection.insert({ text: taskText });
+const insertTask = async (taskText) =>
+ await TasksCollection.insert({ text: taskText });
-Meteor.startup(() => {
- if (TasksCollection.find().count() === 0) {
+Meteor.startup(async () => {
+ if (await TasksCollection.find().countAsync() === 0) {
[
'First Task',
'Second Task',
diff --git a/src/simple-todos/step03/imports/ui/App.svelte b/src/simple-todos/step03/imports/ui/App.svelte
index 64491ba..06f23bf 100644
--- a/src/simple-todos/step03/imports/ui/App.svelte
+++ b/src/simple-todos/step03/imports/ui/App.svelte
@@ -3,20 +3,27 @@
import Task from './Task.svelte';
import TaskForm from './TaskForm.svelte';
- $m: tasks = TasksCollection.find({}, { sort: { createdAt: -1 } }).fetch()
+ let getTasks;
+ $m: getTasks = TasksCollection.find({}, { sort: { createdAt: -1 } }).fetchAsync()
-
+
-
- {#each tasks as task (task._id)}
-
- {/each}
-
+ {#await getTasks}
+
Loading...
+ {:then tasks}
+
+ {#each tasks as task (task._id)}
+
+ {/each}
+
+ {:catch error}
+
{error.message}
+ {/await}
diff --git a/src/simple-todos/step03/imports/ui/TaskForm.svelte b/src/simple-todos/step03/imports/ui/TaskForm.svelte
index d0bdb47..7e51106 100644
--- a/src/simple-todos/step03/imports/ui/TaskForm.svelte
+++ b/src/simple-todos/step03/imports/ui/TaskForm.svelte
@@ -3,9 +3,9 @@
let newTask = '';
- const handleSubmit = () => {
+ const handleSubmit = async () => {
// Insert a task into the collection
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: newTask,
createdAt: new Date(), // current time
});
diff --git a/src/simple-todos/step03/server/main.js b/src/simple-todos/step03/server/main.js
index cd5ce50..896720a 100644
--- a/src/simple-todos/step03/server/main.js
+++ b/src/simple-todos/step03/server/main.js
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TasksCollection';
-const insertTask = taskText => TasksCollection.insert({ text: taskText });
+const insertTask = async (taskText) =>
+ await TasksCollection.insert({ text: taskText });
-Meteor.startup(() => {
- if (TasksCollection.find().count() === 0) {
+Meteor.startup(async () => {
+ if (await TasksCollection.find().countAsync() === 0) {
[
'First Task',
'Second Task',
diff --git a/src/simple-todos/step04/imports/ui/App.svelte b/src/simple-todos/step04/imports/ui/App.svelte
index 64491ba..08c5124 100644
--- a/src/simple-todos/step04/imports/ui/App.svelte
+++ b/src/simple-todos/step04/imports/ui/App.svelte
@@ -3,7 +3,8 @@
import Task from './Task.svelte';
import TaskForm from './TaskForm.svelte';
- $m: tasks = TasksCollection.find({}, { sort: { createdAt: -1 } }).fetch()
+ let getTasks;
+ $m: getTasks = TasksCollection.find({}, { sort: { createdAt: -1 } }).fetchAsync()
@@ -14,9 +15,16 @@
-
- {#each tasks as task (task._id)}
-
- {/each}
-
+
+ {#await getTasks}
+ Loading...
+ {:then tasks}
+
+ {#each tasks as task (task._id)}
+
+ {/each}
+
+ {:catch error}
+ {error.message}
+ {/await}
diff --git a/src/simple-todos/step04/imports/ui/Task.svelte b/src/simple-todos/step04/imports/ui/Task.svelte
index 3ad80ff..3fffb82 100644
--- a/src/simple-todos/step04/imports/ui/Task.svelte
+++ b/src/simple-todos/step04/imports/ui/Task.svelte
@@ -3,15 +3,15 @@
export let task;
- const toggleChecked = () => {
+ const toggleChecked = async () => {
// Set the checked property to the opposite of its current value
- TasksCollection.update(task._id, {
+ await TasksCollection.updateAsync(task._id, {
$set: { isChecked: !task.isChecked }
});
};
- const deleteThisTask = () => {
- TasksCollection.remove(task._id);
+ const deleteThisTask = async () => {
+ await TasksCollection.removeAsync(task._id);
};
diff --git a/src/simple-todos/step04/imports/ui/TaskForm.svelte b/src/simple-todos/step04/imports/ui/TaskForm.svelte
index d0bdb47..7e51106 100644
--- a/src/simple-todos/step04/imports/ui/TaskForm.svelte
+++ b/src/simple-todos/step04/imports/ui/TaskForm.svelte
@@ -3,9 +3,9 @@
let newTask = '';
- const handleSubmit = () => {
+ const handleSubmit = async () => {
// Insert a task into the collection
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: newTask,
createdAt: new Date(), // current time
});
diff --git a/src/simple-todos/step04/server/main.js b/src/simple-todos/step04/server/main.js
index cd5ce50..896720a 100644
--- a/src/simple-todos/step04/server/main.js
+++ b/src/simple-todos/step04/server/main.js
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TasksCollection';
-const insertTask = taskText => TasksCollection.insert({ text: taskText });
+const insertTask = async (taskText) =>
+ await TasksCollection.insert({ text: taskText });
-Meteor.startup(() => {
- if (TasksCollection.find().count() === 0) {
+Meteor.startup(async () => {
+ if (await TasksCollection.find().countAsync() === 0) {
[
'First Task',
'Second Task',
diff --git a/src/simple-todos/step05/imports/ui/App.svelte b/src/simple-todos/step05/imports/ui/App.svelte
index c2d2f8a..b7d8ecf 100644
--- a/src/simple-todos/step05/imports/ui/App.svelte
+++ b/src/simple-todos/step05/imports/ui/App.svelte
@@ -3,7 +3,8 @@
import Task from './Task.svelte';
import TaskForm from './TaskForm.svelte';
- $m: tasks = TasksCollection.find({}, { sort: { createdAt: -1 } }).fetch()
+ let getTasks;
+ $m: getTasks = TasksCollection.find({}, { sort: { createdAt: -1 } }).fetchAsync()
@@ -18,11 +19,16 @@
-
-
- {#each tasks as task (task._id)}
-
- {/each}
-
+ {#await getTasks}
+
Loading...
+ {:then tasks}
+
+ {#each tasks as task (task._id)}
+
+ {/each}
+
+ {:catch error}
+
{error.message}
+ {/await}
diff --git a/src/simple-todos/step05/imports/ui/Task.svelte b/src/simple-todos/step05/imports/ui/Task.svelte
index 3ad80ff..3fffb82 100644
--- a/src/simple-todos/step05/imports/ui/Task.svelte
+++ b/src/simple-todos/step05/imports/ui/Task.svelte
@@ -3,15 +3,15 @@
export let task;
- const toggleChecked = () => {
+ const toggleChecked = async () => {
// Set the checked property to the opposite of its current value
- TasksCollection.update(task._id, {
+ await TasksCollection.updateAsync(task._id, {
$set: { isChecked: !task.isChecked }
});
};
- const deleteThisTask = () => {
- TasksCollection.remove(task._id);
+ const deleteThisTask = async () => {
+ await TasksCollection.removeAsync(task._id);
};
diff --git a/src/simple-todos/step05/imports/ui/TaskForm.svelte b/src/simple-todos/step05/imports/ui/TaskForm.svelte
index d0bdb47..7e51106 100644
--- a/src/simple-todos/step05/imports/ui/TaskForm.svelte
+++ b/src/simple-todos/step05/imports/ui/TaskForm.svelte
@@ -3,9 +3,9 @@
let newTask = '';
- const handleSubmit = () => {
+ const handleSubmit = async () => {
// Insert a task into the collection
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: newTask,
createdAt: new Date(), // current time
});
diff --git a/src/simple-todos/step05/server/main.js b/src/simple-todos/step05/server/main.js
index cd5ce50..896720a 100644
--- a/src/simple-todos/step05/server/main.js
+++ b/src/simple-todos/step05/server/main.js
@@ -1,10 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TasksCollection';
-const insertTask = taskText => TasksCollection.insert({ text: taskText });
+const insertTask = async (taskText) =>
+ await TasksCollection.insert({ text: taskText });
-Meteor.startup(() => {
- if (TasksCollection.find().count() === 0) {
+Meteor.startup(async () => {
+ if (await TasksCollection.find().countAsync() === 0) {
[
'First Task',
'Second Task',
diff --git a/src/simple-todos/step06/imports/ui/App.svelte b/src/simple-todos/step06/imports/ui/App.svelte
index 0df1f71..c87260f 100644
--- a/src/simple-todos/step06/imports/ui/App.svelte
+++ b/src/simple-todos/step06/imports/ui/App.svelte
@@ -6,21 +6,19 @@
let hideCompleted = false;
const hideCompletedFilter = { isChecked: { $ne: true } };
-
- let incompleteCount;
- let pendingTasksTitle = '';
- let tasks = [];
+ let getTasks;
+ let getCount;
$m: {
- tasks = TasksCollection.find(hideCompleted ? hideCompletedFilter : {}, {
+ getTasks = TasksCollection.find(hideCompleted ? hideCompletedFilter : {}, {
sort: { createdAt: -1 },
- }).fetch();
-
- incompleteCount = TasksCollection.find(hideCompletedFilter).count();
+ }).fetchAsync();
- pendingTasksTitle = `${incompleteCount ? ` (${incompleteCount})` : ''}`;
+ getCount = TasksCollection.find(hideCompletedFilter).countAsync();
}
+ const pendingTitle = (count) => `${count ? ` (${count})` : ''}`;
+
const setHideCompleted = (value) => {
hideCompleted = value;
};
@@ -30,7 +28,11 @@
@@ -42,10 +44,16 @@
{hideCompleted ? 'Show All' : 'Hide Completed'}
-
- {#each tasks as task (task._id)}
-
- {/each}
-
+ {#await getTasks}
+ Loading...
+ {:then tasks}
+
+ {#each tasks as task (task._id)}
+
+ {/each}
+
+ {:catch error}
+ {error.message}
+ {/await}
diff --git a/src/simple-todos/step06/imports/ui/Task.svelte b/src/simple-todos/step06/imports/ui/Task.svelte
index 3ad80ff..43911f6 100644
--- a/src/simple-todos/step06/imports/ui/Task.svelte
+++ b/src/simple-todos/step06/imports/ui/Task.svelte
@@ -3,24 +3,24 @@
export let task;
- const toggleChecked = () => {
+ const toggleChecked = async () => {
// Set the checked property to the opposite of its current value
- TasksCollection.update(task._id, {
+ await TasksCollection.updateAsync(task._id, {
$set: { isChecked: !task.isChecked }
});
};
- const deleteThisTask = () => {
- TasksCollection.remove(task._id);
+ const deleteThisTask = async () => {
+ await TasksCollection.removeAsync(task._id);
};
{ task.text }
diff --git a/src/simple-todos/step06/imports/ui/TaskForm.svelte b/src/simple-todos/step06/imports/ui/TaskForm.svelte
index d0bdb47..0f1bc86 100644
--- a/src/simple-todos/step06/imports/ui/TaskForm.svelte
+++ b/src/simple-todos/step06/imports/ui/TaskForm.svelte
@@ -1,18 +1,18 @@