I can't seem to get reactive collection changes from server side using the following code:
Template.name.onRendered(function() {
this.autorun(function(){
Meteor.subscribe("items", Session.get("start"), Session.get("end"), function () {
//update UI
});
});
});
When Session.get("start")
changed, it will subscribe all the items within the range from server correctly, but if I delete a item from mongo shell, the subscription callback won't be called, i.e. that re-subscription is not triggered at client side, I need to get these two conditions working,
- WHEN Session.get("start"), Session.get("end") changed THEN get data within range from server(I do this with subscribe) and update UI
- WHEN the query result Items.find(start, end) changed (server side changes to the collection) THEN also update UI
I can almost get these working by using another autorun to track the Items.find() query,
Template.name.onRendered(function() {
// when user changed the date range, get the new data
this.autorun(function(){
Meteor.subscribe("items", Session.get("start"), Session.get("end"), function () {
//update UI
});
});
// get all the changes from server and update UI
this.autorun(function(){
Items.find(start, end);
//update UI
});
});
but seems after each subscription completes, the query autorun also runs, which is not necessary, it's really supposed to only pick changes from server, what should I do to reflect any changes within range at server side to the client?