javascript - Preventing Meteor from removing MiniMongo data already sent to client when publish changes -


i have noticed when change published cursor - not data cursor points to, whole cursor - meteor send removed message client documents not appear in new cursor. mean in more technical terms:

// client side tracker.autorun(function() {     var somereactivevar = somereactivevar.get();      meteor.subscribe('mypublication', somereactivevar); } ... // server side meteor.publish('mypublication', function() {     var someparameter = arguments[0];     return mycollection.find({ someattribute: someparameter }); }); 

now when somereactivevar changes, documents had been sent client side minimongo mycollection removed (if not part of new cursor). in cases want, question is: can prevent this? how?

there's magic happening here, when perform meteor.subscribe inside tracker.autorun. basically, .stop() old subscription after each run.

you have 2 options,

1- keep multiple subscriptions alive, using nonreactive block.

note: you'll have write code clean-up subhandles.

var subhandles = []; tracker.autorun(function(){   var somereactiveval = somereactivevar.get();   tracker.nonreactive(function(){     var subhandle = meteor.subscribe('mypublication', somereactiveval);     subhandles.push(subhandle);   }); }); 

2- make subscription take multiple values, eg

note: make both sets of data available on client, may not stop being re-transmitted.

template.mytemplate.events({    'click mybutton': function(){       var newval = getnewval();       var arrayofvalues = somereactivevar.get();       arrayofvalues.push(newval);       somereactivevar.set(arrayofvalues);    } })  // client side tracker.autorun(function() {     var arrayofvalues = somereactivevar.get();      meteor.subscribe('mypublication', arrayofvalues); } ... // server side meteor.publish('mypublication', function(arrayofvalues) {     return mycollection.find({        someattribute: {$in: arrayofvalues}      }); }); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -