Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can restart Count? #69

Closed
the-evgenii opened this issue Sep 15, 2015 · 3 comments
Closed

How can restart Count? #69

the-evgenii opened this issue Sep 15, 2015 · 3 comments

Comments

@the-evgenii
Copy link

Hey!
I have some publication function, like this:

Meteor.reactivePublish('postsCount', function() {
  if (this.userId) {
    var user = Meteor.users.findOne({
      _id: this.userId
    }, {
      reactive: true
    });

    if (!!user.team) {
      var team = Teams.findOne({
        _id: user.team
      });

      if (team && team.owner === user._id) {
        Counts.publish(this, 'postsCounter', Posts.find({
          $or: [
            {
              owner: user.team,
              shared: true,
              archive: false
            }, {
              owner: user.team,
              shared: false,
              archive: false
            }, {
              owner: this.userId,
              shared: false,
              archive: false
            }
          ]
        }));
      }

      Counts.publish(this, 'postsCounter', Posts.find({
        $or: [
          {
            owner: user.team,
            shared: true,
            archive: false
          }, {
            owner: this.userId,
            shared: false,
            archive: false
          }
        ]
      }));
    }

    Counts.publish(this, 'postsCounter', Posts.find({
      owner: this.userId,
      shared: false,
      archive: false
    }));
  }

  this.ready();
});

renaming or removing field 'team' from user record does not trigger update event for counter

Update 20150920: reformat and add syntax highlighting --boxofrox

@the-evgenii
Copy link
Author

This is two screeshots what i mean
2015-09-15 16-49-00 mongochef 3t software labs non-commercial license
2015-09-15 16-49-35 mongochef 3t software labs non-commercial license

console.log(cursor.count());
Counts.publish(this, 'PostsCounter', cursor);

console.log tells me about changed count, but Counts tells me no

@boxofrox
Copy link
Contributor

I don't understand what you're trying to achieve with your example.

When all your if block conditions pass, then you redefine one named count three times. If you need three counters for one user subscription, then give them different names (see #66).

If you left out else blocks, please add them and try to keep the code indented so we can read it easily.

Based on the example code provided, two or more counts are dumping their values under one name. That last counter doesn't appear to be affected by changes to the team field.

@the-evgenii
Copy link
Author

Tnx for you answer boxofrox. But I am create my counter without this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants