Hello,
I am asking this out of curiosity, so please bear with me
After learning the core about publication/subscription and methods on the meteor docs i got to know that both of these can be used to fetch data and the former is better for reactively updating the client database.
Ok, But before this I had a method that used to fetch data from Meteor.users() collection
Meteor.methods({
'fetchUsers' : function() {
return Meteor.users.find();
}
})
I used to call this method from Template.onCreated and getting the result from callback into template helper reactively using ReactiveVar
Template.homescreen.onCreated(function(){
var self = this;
self.usersVar = new ReactiveVar();
Meteor.call('fetchUsers',function(err,res){
if(!err)
self.usersVar.set(res);
else
console.log(err);
});
});
And in the template helper
Template.homescreen.helpers ({
'users' : function() {
return this.usersVar.get();
}
});
All this code was working perfectly until I removed autopublish and published the same data from the server and subscribed to it globally on the client.
So all in all, I mixed both ways, i.e methods and pub/sub but what I got after mixing both was pretty unusual.
In some cycle, the data was fetched, i.e it rendered correctly and i some it did not.
So each time i reloaded the page, I didn’t know whether the fetch would be successful this time or not.
Pretty strange
So I wanted to know if anyone could help me explain this unusual behaviour.
Btw, Both the ways methods and pub/sub are working fine if done individually.
Thanks in advance