meteor Publishing Data Reactively re-subscribing to a publication


Example

A template autorun may be used to (re)subscribe to a publication. It establishes a reactive context which is re-executed whenever any reactive data it depends on changes. In addition, an autorun always runs once (the first time it is executed).

Template autoruns are normally put in an onCreated method.

Template.myTemplate.onCreated(function() {
  this.parameter = new ReactiveVar();
  this.autorun(() => {
    this.subscribe('myPublication', this.parameter.get());
  });
});

This will run once (the first time) and set up a subscription. It will then re-run whenever the parameter reactive variable changes.