Skip to content

Commit 50de8ee

Browse files
authored
Merge pull request #35 from meteor/feature-mongo-async
Feature mongo async
2 parents ca0aa3c + 990fa0e commit 50de8ee

File tree

45 files changed

+329
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+329
-315
lines changed

src/simple-todos/step02/server/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Meteor } from 'meteor/meteor';
22
import { TasksCollection } from '/imports/api/TasksCollection';
33

4-
const insertTask = taskText => TasksCollection.insert({ text: taskText });
4+
const insertTask = async (taskText) =>
5+
await TasksCollection.insertAsync({ text: taskText });
56

6-
Meteor.startup(() => {
7-
if (TasksCollection.find().count() === 0) {
7+
Meteor.startup(async () => {
8+
if (TasksCollection.find().countAsync() === 0) {
89
[
910
'First Task',
1011
'Second Task',

src/simple-todos/step03/imports/ui/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Template.mainContainer.helpers({
99
});
1010

1111
Template.form.events({
12-
'submit .task-form'(event) {
12+
async 'submit .task-form'(event) {
1313
// Prevent default browser form submit
1414
event.preventDefault();
1515

@@ -18,7 +18,7 @@ Template.form.events({
1818
const text = target.text.value;
1919

2020
// Insert a task into the collection
21-
TasksCollection.insert({
21+
await TasksCollection.insertAsync({
2222
text,
2323
createdAt: new Date(), // current time
2424
});

src/simple-todos/step03/server/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Meteor } from 'meteor/meteor';
22
import { TasksCollection } from '/imports/api/TasksCollection';
33

4-
const insertTask = taskText => TasksCollection.insert({ text: taskText });
4+
const insertTask = async (taskText) =>
5+
await TasksCollection.insertAsync({ text: taskText });
56

6-
Meteor.startup(() => {
7-
if (TasksCollection.find().count() === 0) {
7+
Meteor.startup(async () => {
8+
if (TasksCollection.find().countAsync() === 0) {
89
[
910
'First Task',
1011
'Second Task',

src/simple-todos/step04/imports/ui/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Template.mainContainer.helpers({
1010
});
1111

1212
Template.form.events({
13-
'submit .task-form'(event) {
13+
async 'submit .task-form'(event) {
1414
// Prevent default browser form submit
1515
event.preventDefault();
1616

@@ -19,7 +19,7 @@ Template.form.events({
1919
const text = target.text.value;
2020

2121
// Insert a task into the collection
22-
TasksCollection.insert({
22+
await TasksCollection.insertAsync({
2323
text,
2424
createdAt: new Date(), // current time
2525
});

src/simple-todos/step04/imports/ui/Task.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { TasksCollection } from '../api/TasksCollection';
55
import './Task.html';
66

77
Template.task.events({
8-
'click .toggle-checked'() {
8+
async 'click .toggle-checked'() {
99
// Set the checked property to the opposite of its current value
10-
TasksCollection.update(this._id, {
10+
await TasksCollection.updateAsync(this._id, {
1111
$set: { isChecked: !this.isChecked },
1212
});
1313
},
14-
'click .delete'() {
15-
TasksCollection.remove(this._id);
14+
async 'click .delete'() {
15+
await TasksCollection.removeAsync(this._id);
1616
},
1717
});

src/simple-todos/step04/server/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Meteor } from 'meteor/meteor';
22
import { TasksCollection } from '/imports/api/TasksCollection';
33

4-
const insertTask = taskText => TasksCollection.insert({ text: taskText });
4+
const insertTask = async (taskText) =>
5+
await TasksCollection.insertAsync({ text: taskText });
56

6-
Meteor.startup(() => {
7-
if (TasksCollection.find().count() === 0) {
7+
Meteor.startup(async () => {
8+
if (TasksCollection.find().countAsync() === 0) {
89
[
910
'First Task',
1011
'Second Task',

src/simple-todos/step05/imports/ui/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Template.mainContainer.helpers({
1010
});
1111

1212
Template.form.events({
13-
'submit .task-form'(event) {
13+
async 'submit .task-form'(event) {
1414
// Prevent default browser form submit
1515
event.preventDefault();
1616

@@ -19,7 +19,7 @@ Template.form.events({
1919
const text = target.text.value;
2020

2121
// Insert a task into the collection
22-
TasksCollection.insert({
22+
await TasksCollection.insertAsync({
2323
text,
2424
createdAt: new Date(), // current time
2525
});

src/simple-todos/step05/imports/ui/Task.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { TasksCollection } from '../api/TasksCollection';
55
import './Task.html';
66

77
Template.task.events({
8-
'click .toggle-checked'() {
8+
async 'click .toggle-checked'() {
99
// Set the checked property to the opposite of its current value
10-
TasksCollection.update(this._id, {
10+
await TasksCollection.updateAsync(this._id, {
1111
$set: { isChecked: !this.isChecked },
1212
});
1313
},
14-
'click .delete'() {
15-
TasksCollection.remove(this._id);
14+
async 'click .delete'() {
15+
await TasksCollection.removeAsync(this._id);
1616
},
1717
});

src/simple-todos/step05/server/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Meteor } from 'meteor/meteor';
22
import { TasksCollection } from '/imports/api/TasksCollection';
33

4-
const insertTask = taskText => TasksCollection.insert({ text: taskText });
4+
const insertTask = async (taskText) =>
5+
await TasksCollection.insertAsync({ text: taskText });
56

6-
Meteor.startup(() => {
7-
if (TasksCollection.find().count() === 0) {
7+
Meteor.startup(async () => {
8+
if (TasksCollection.find().countAsync() === 0) {
89
[
910
'First Task',
1011
'Second Task',

src/simple-todos/step06/imports/ui/App.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ Template.mainContainer.events({
1818
});
1919

2020
Template.mainContainer.helpers({
21-
tasks() {
21+
async tasks() {
2222
const instance = Template.instance();
2323
const hideCompleted = instance.state.get(HIDE_COMPLETED_STRING);
2424

2525
const hideCompletedFilter = { isChecked: { $ne: true } };
2626

27-
return TasksCollection.find(hideCompleted ? hideCompletedFilter : {}, {
27+
return await TasksCollection.find(hideCompleted ? hideCompletedFilter : {}, {
2828
sort: { createdAt: -1 },
29-
}).fetch();
29+
}).fetchAsync();
3030
},
3131
hideCompleted() {
3232
return Template.instance().state.get(HIDE_COMPLETED_STRING);
3333
},
34-
incompleteCount() {
35-
const incompleteTasksCount = TasksCollection.find({
34+
async incompleteCount() {
35+
const incompleteTasksCount = await TasksCollection.find({
3636
isChecked: { $ne: true },
37-
}).count();
37+
}).countAsync();
3838
return incompleteTasksCount ? `(${incompleteTasksCount})` : '';
3939
},
4040
});
4141

4242
Template.form.events({
43-
'submit .task-form'(event) {
43+
async 'submit .task-form'(event) {
4444
// Prevent default browser form submit
4545
event.preventDefault();
4646

@@ -49,7 +49,7 @@ Template.form.events({
4949
const text = target.text.value;
5050

5151
// Insert a task into the collection
52-
TasksCollection.insert({
52+
await TasksCollection.insertAsync({
5353
text,
5454
createdAt: new Date(), // current time
5555
});

0 commit comments

Comments
 (0)