meteor - Know when child templates have been rendered -


<template name="frameitems">   <div class="frame-items">     {{#each frames}}       {{> frameitem}}     {{/each}}   </div> </template> 

in above example, want know when frameitem templates inside frameitems template have been rendered. thought onrendered of parent invoked when child templates have been rendered, called right away. what's conventional way of making sure child templates rendered?

one way use counter , increment until reaches value.
here counter in session , incremented until reaches length of frames iterable thing:

template.frameitems.onrendered(function() {   session.set('framecounter', 0); });  template.frameitem.onrendered(function() {   session.set('framecounter', session.get('framecounter') + 1); }); 

then use tracker:

//where template template instance, example 'this' in oncreated callback template.autorun(function dostuffwhenframesrendered(computation) {   if(session.get('framecounter') === template.frames.length) {     dostuff();     //stop observing     computation.stop();   } }); 

note takes account fact frameitem may render @ weird times (avoiding race conditions if any), doesn't take account new frames. take account not stop computation.


Comments