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
Post a Comment