Animating a session that's in an interval in Meteor?


I have Meteor.setInterval find one recent item in my collection and then sets it in a session every 1 seconds.

Meteor.setInterval(function() {
  var entries = Database.findOne({}, { sort: { date: -1} });
    Session.set('entryName', entries); 
}, 1200);

I need this as it only gets the most recent entry and prevents flooding of other entries as it fires only once a second. Is there anyway of animating this (lets say add a fade effect)? Its a problem because if I animate to the interval, it will fade in and out every second, even if a new entry hasn’t been added.

I need it to fade only if the entry changes. Is there maybe a better way of rewriting the code in a Meteor way so its easier to animate?


Hello @sflowerlisa22,

I would use meteor add matb33:collection-hooks and set your entryName in after.insert hook

var test = new Mongo.Collection(“database”);
test.after.insert(function (userId, doc) {
Session.set(‘entryName’, doc);

So you always have the last entry updated; no need for interval.