Template subscriptions and autorun

Funny, if I use another tracker.autorun inside it works… But I am a bit lost now :slight_smile:

  • why is this happening?
  • what is the difference between tracker.autorun and this.autorun?
  • is the issue in my previous code, that I have put the subscription to apps in the callback function on the GeneratedResources collection on which it has a dependency?

thank you

Template.generation.onCreated(function() {
    this.subscribe('streams');
    this.subscribe('customers');

    var self = this;
    self.autorun(function() {
        self.subscribe('generatedResources', function() {
            console.log('generatedResources changed, so update the apps subscription');
            Tracker.autorun(function() {
                const generatedAppsFromUser = GeneratedResources.find()
                    .map(function(resource) {
                        return resource.appId;
                    });
                console.log('onCreated generatedResources are: ', generatedAppsFromUser);
                //now get all the apps from Qlik Sense, but filter them so that only the apps are show which the current user has generated
                Meteor.subscribe('apps', generatedAppsFromUser);
            })

        });
    })
})

Source: http://stackoverflow.com/questions/29443513/meteor-tracker-autorun-observechanges-collections-not-working-as-expected