javascript - Meteor: How to trigger reRun of helper function after collectionHandle.ready() is true -


this new version of old question:

so tom coleman's figured out on how check if subscription ready() or not.

my current code structure looks this:

/client/app.js:  eventshandle = null; groupshandle = null; // ... // first deps.autorun(): // not depend on session var, should run every time deps.autorun(function() {     eventshandle = meteor.subscribe("events", function() {         console.log('deps.autorun(): events loaded');     }); });  // second deps.autorun(): // contains subscriptions dependent on session var "ehash" deps.autorun(function() {     if(session.get('ehash'))         groupshandle = meteor.subscribe("groups", session.get('ehash'), function() {             console.log('deps.autorun(): groups loaded ehash: ' + session.get('ehash'));         }); }); // ... 

then have view specific .js , .html files template stuff in 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 in corresponding template , shows content when dataloaded returns true or else shows loading spinner.

problem in many cases not work because dataloaded code run once. if 2 handles not ready() @ time dataloaded run, content never show up. in case still see console.log's coming app.js file (the deps.autorun() stuff) log "all data loaded!" never echod.

so question is: how trigger rerun of code dataloaded run again content show up?

best regards

the problem can solved creating dependency:

var _dep = new deps.dependency();  template.x.dataloaded = function() {     _dep.depend();     ... }   function handler() {     ... do.stuff();     _dep.changed(); } 

now, every time run _dep.changed() method, helper rerun. simple!


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -