javascript - Make a meteor publication reactive to time -


i'm having little trouble figuring out how make subscription reactive publication query.

my publication follows:

meteor.publish('alldata', function(){     return data.find({ttl: {$gt: new date()}}) }) 

as can see, documents contain ttl field. long time live still greater current time, can sent client, if not, shouldn't.

the subscription:

this.autorun(() => {     this.subscribe('alldata') }) 

on initial load, data fine, whenever ttl expires, document remains on client unless reload page. there anyway handle reactively, making expired documents disappear client?

a combination of reactivevar , autorun did trick me. it's possible overkill, works.

let cutofftimestamp = new reactivevar();  meteor.setinterval(function() {     cutofftimestamp.set(date.now() - 1); }, 60000);  meteor.publish("mypub", function() {     this.autorun(function() {         return mycollection.find({ timestamp: { $gte: cutofftimestamp.get(); } });     }); }); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -