bigbite / macy.js

http://macyjs.com/
MIT License
1.3k stars 156 forks source link

Macy.init happening too early #8

Closed alro5 closed 7 years ago

alro5 commented 8 years ago

Hello,

I'm having trouble initialising Macy. I'm working on an angular app, and I'm building a blog system. The blog page is requesting an endpoint and displaying the blogposts in an ng-repeat.

The data is being loaded, and then we're trying to init Macy after this request.

So in our success call, we're firing Macy after the data is loaded

I can solve this by a timeout, but this is not a bulletproof solution.

Hope you can help!

renatogalvones commented 7 years ago

@alro5 I had the same problem here using react and I was able to solve it using the "timeout,0 solution"

window.setTimeout(() => {
  Macy.init(macyProps);
  return true;
}, 0);

Here's some explanation about the concept behind of it.

https://stackoverflow.com/questions/779379/why-is-settimeoutfn-0-sometimes-useful/779785#779785

jrmd commented 7 years ago

After looking into the reason why this happens, I feel like this is more the issue on how javascript works. Closing due to a successful workaround.