This seemingly simple issue has been causing me some trouble.
With the code provided below, I am able to increase or decrease the number of likes on my posts by 1.
I am looking to achieve the following:
If postLikes = 0, then prevent further reduction of likes
It should not be possible to bring the number of likes below 0.
Below is the code snippet in question:
Template.post.events({
"click .likeButton": function() {
// Set the checked property to the opposite of its current value
Posts.update(this._id, {
$inc: {
postLikes: 1
}
});
},
"click .dislikeButton": function() {
// Set the checked property to the opposite of its current value
Posts.update(this._id, {
$inc: {
postLikes: -1
}
});
}
});