This a new version of my old question:
So thanks to Tom Coleman's help I finally figured out on how to properly check if a subscription is ready() or not.
My current code structure looks like this:
/client/app.js:
eventsHandle = null;
groupsHandle = null;
// ...
// First Deps.autorun():
// Does not depend on any Session var, should just run every time
Deps.autorun(function() {
eventsHandle = Meteor.subscribe("events", function() {
console.log('Deps.autorun(): Events loaded');
});
});
// Second Deps.autorun():
// contains all subscriptions which are dependent on my Session var "ehash"
Deps.autorun(function() {
if(Session.get('ehash'))
groupsHandle = Meteor.subscribe("groups", Session.get('ehash'), function() {
console.log('Deps.autorun(): Groups loaded with ehash: ' + Session.get('ehash'));
});
});
// ...
Then I have view specific .js and .html files for all the template stuff in a folder called:
/client/views/
--> <page>.js:
Template.x.dataLoaded = function() {
if(Session.get('ehash'))
if(eventsHandle && groupsHandle && eventsHandle.ready() && groupsHandle.ready()) {
console.log('All data loaded!');
singleevent = Events.find({ehash: Session.get('ehash')}).fetch()[0];
return true;
}
}
This helper dataLoaded
wraps basically everything in the corresponding template and shows the content when dataLoaded
returns true or else shows a loading spinner.
Problem is that in many cases this does not work because this dataLoaded code is only run once. So if the two handles are NOT ready() at the time dataLoaded is run, content will NEVER show up. In this case I still see all the console.log's coming from the app.js file (the Deps.autorun() stuff) but the log "All data loaded!" is never echod.
So my question is: How do I trigger a rerun of this code so dataLoaded
is run again so content will eventually show up?
best regards