user3475602
user3475602

Reputation: 1217

Counter-Up not increasing int in Meteor application

I am using the Counter-Up plugin for my Meteor application. On first site load it works fine, but there seems to be a problem with real-time changes.

I want to display total games created in my web app, so I have this helper:

totalGames: function () {
     return Games.find().count();
}

and this is my rendered function:

Template.home.rendered = function () {
    $('.counter').counterUp({
        delay: 10,
        time: 500
    });
};

Now the problem is, the counter does not increase, due to the reactivity. So if user A sees the counter with the number 1 on the home site and suddenly a new game is created, the number changes to 12 and not 2.

How can I solve this issue? Any help would be greatly appreciated.

Upvotes: 0

Views: 92

Answers (2)

David Weldon
David Weldon

Reputation: 64312

Give this a try:

Template.home.rendered = function() {
  this.autorun(function() {
    if (Template.currentData() && Games.find().count())
      $('.counter').counterUp({delay: 10, time: 500});
  });
};

In theory, this should rerun the counterUp initialization any time the Games count changes. The Template.currentData business is just a hack to make the the autorun work inside of rendered - see my related answer here.

Upvotes: 1

TheBetterJORT
TheBetterJORT

Reputation: 808

When I get this behavior I run this. I've also run into issues with randomness. The delay is caused by the minimongo which sits on your browser not getting the correct cache from mongodb.

Here are things that I do to kick start the ddp to get the data through the wire.

1) I close out of the terminal. This should have 0 affect, but sometimes things get hung up. Just Try it.

2) rm -rf ~/[name of project].meteor/local/.mirror

3) double check I saved my changes.

Upvotes: 0

Related Questions