I am confused because I have an autorun in Meteor-Angular and I need to subcribe each time the variable this.getReactively(‘perPage’) changes, but before I need to verified if Meteor.user() exists, so I need to put it inside of the funtion autorun, but my problem is that this autorun runs each time not just when this.getReactively(‘perPage’) changes but when Meteor. user changes, I dont know if there is a way to avoid that, maybe compare previous value of Meteor.user, I dont know. Someone could help me? thanks
When you do a set on your getReactively could you include the user notifications_bell in the value? Then the autorun would not need to call Meteor.user().
I have no idea how your code is written or what getReactively is, but here is some pseudo code:
// where reactiveVar is set
reactiveVar.set({notifications_bell: Meteor.user().notifications_bell, perPageStuff: getPerPageStuff()});
...
// now autorun can look like this
Tracker.autorun(function() {
let reactiveData = this.getReactively('per'Page);
if(reactiveData.perPageStuff) {
console.log(this.getReactively('perPage'));
Meteor.subscribe('notifications_bell',reactiveData.notifications_bell, reactiveData.perPageStuff);
}
}.bind(this));
Note: you might want to check into the reactive-dict package, maybe getReactively is a dictionary lookup?
Try using Meteor.userId() for the first condition - then it will only re-run if the currently logged in user changes. Meteor.userId() returns null when nobody is logged in, so your code will work as is.
For the second thing, you can use a Minimongo query with fields: