Right now the initial code that comes with a new Meteor project uses Session
to increment a counter when a button is clicked.
But what about changing the demo to using a Mongo Collection instead? That way you also demonstrate the live syncing of data across multiple clients. What if we change the javascript file included in new projects to this?
Clicks = new Mongo.Collection("clicks");
if (Meteor.isClient) {
Template.hello.helpers({
counter: function () {
var click = Clicks.findOne();
if (click)
return click.clicks;
}
});
Template.hello.events({
'click button': function () {
var click = Clicks.findOne();
if (click)
Clicks.update({_id: click._id}, {$inc: {clicks: 1}});
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
Clicks.remove({});
Clicks.insert({clicks: 0});
});
}
Or is that too much of a leap for a first time project?