Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor: Tracker.autorun when Iron-Router Data Updates

I'm using iron-router's data function to provide data to my HTML template.

snippet from router.js:

data: function() {
    liveData = {
      dataA: Collection.findOne({queryA}),
      dataB: Collection.findOne({queryB})
    };
    return liveData;
}

Within my template, the liveData object is reactive. When the Collection changes, liveData changes - great!

But my question: I have a javascript function called computation() within Template.name.rendered which uses the liveData object. It runs once on page load - great - but after the page is loaded, liveData is changing but the computation is not being re-run. How do I force computation() to re-run when iron-router's data source, liveData, changes?

like image 447
Jon Cursi Avatar asked Feb 01 '26 06:02

Jon Cursi


1 Answers

Template.name.rendered = function(){
  this.autorun(function(){
    var data = Router.current().data();
    computation(data);
  });
}
like image 194
Kuba Wyrobek Avatar answered Feb 02 '26 22:02

Kuba Wyrobek