True ready event or helpers render callback?

Hi,

I’m looking for a simple solution to execute a function when my helpers has finish to rendered my content…

My case…

I have a form and I load the fields from a pub/subscription… Then I have to do some action on the fields from the url parameters…

So, my helpers load the fields in my page…
Then I want to execute a function when the form is ready…

I tried to execute my function on Template.myTemplate.onRendered() but it’s not working… as the content is not really ready…

I tested with an autorun… but same result…

It work only if I use a setTimeout() … but it’s not what I’m looking for.

Do you know how to execute a function only when the helpers has finish to render a content ?

I also tried to use a subscription callback… but there is still the rendered delay from the helpers… so it should have a helpers callback I think…?

Thanks for your help,

Mike

Sounds like you should be passing the url params in as data/props to your template from the router, and controlling the rendering from there, separating the ‘smart’ component from the reusable one.

Actually, if you separate out the data loading as well, you can fetch all the content and pass it down to the component when it’s all loaded and then onRendered will fire after the entire DOM of that component is built

Can you be more specific about what you want to do after the template has fully rendered?

A filthy hack that always works is to throw a

Tracker.afterFlush(function () { ... });

in the helper before it returns. Just make sure that the function isn’t doing anything too elaborate if the helper is getting called multiple times. :grinning:

1 Like