Search code examples
meteormeteor-blazeautorun

Detecting if template was re-rendered due to data context change


Here's a pretty common pattern:

Template.myTemplate.rendered = function () {
  this.autorun(function () {
    var selector = {}; // should depend on the current data context
    MyCollection.find(selector).observe({
      // ...
    });
  });
}

In general, I want the selector value depend on the current data context, which may potentially change, but we all know that the rendered routine will not be called again, so I don't even try to mess with that. Instead I hope I could invalidate the computation inside autorun by accessing the current data context reactively, which seems to be quite a natural thing to do. However it seems it's not documented anywhere (or I am missing something).

If anyone has an idea how to access the current data context reactively, please share.


Solution

  • Template.currentData(): http://docs.meteor.com/#/full/template_currentdata

    I think it does exactly what you are looking for.