Avoid SetTimeout

Hi all:

Im really new in meteor and I realized that sometimes in client side the data is not complete (apparently), so many times I have had to use setTimeout function to put a little delay and wait for it, before doing something.
I have faced this situation with some libraries and onrendered event too.

How can I avoid this situation ? Is this normal ?
Tip: At the moment Im not using publish and subscribe, maybe this could solve the first case.

Many thanks,

The only place where we needed to do that was in onRendered as the browser has not completely rendered the DOM (or maybe jQuery has not yet run its magic). Personally I use _.defer(function() { }) and only use timeouts when there is a real delay somewhere I can’t get around (can’t think of any at the moment, but they are exceptions not the rule).

I’m also having to setTimeout for like 300-500 on some events. Really annoying. Waiting for a smartr person to give us a solution :slight_smile:

Can you give an example of how you are using this. Not sure why this would be necessary.

1 Like

For example on TinyMCE.

If I call $("#SomeContentBox").TinyMce(“init”) or whatever on Meteor OnRendered it will not work.

I must set the init to a 300-500 second timeout for everything to load to DOM. So I wait 300 and the code seems to work.

This is due to a poor understanding of DOM and loading events I suppose. It’s a hack until then.

Is the rendering of someContentBox data dependant?

Nope, just a regular text input.

So therefor, just a proper useage is all that’s required. This is clearly a hack.

You are right, definitely a hack and should not be necessary. If either of you have an open repository or a reproduction of the issue I’d be more than happy to take a look.