Fork me on GitHub
#reagent
<
2015-07-26
>
lucien.knechtli02:07:37

Can anyone tell me why adding window.onload = function(){ app.core.main();} to the html served by my application will cause it to get an error similar to this: https://www.refheap.com/107001 , but calling the main method inside the actual cljs file will initialize everything properly? Here's a stripped down version of the cljs: https://www.refheap.com/107002 (only 16 lines)

xhh03:07:40

@lucien.knechtli: maybe due to the <div id=“app”> element is not ready on window.onload

xhh03:07:10

you can call app.core.main() in a timeout function to confirm

xhh03:07:47

e.g. setTimeout(function(){ app.core.main(); }, 1000);

lucien.knechtli03:07:24

Isn't window. onload supposed to fire after all the assets have been downloaded? Doing a timeout seems like a really hacky workaround ...

lucien.knechtli03:07:42

or are you saying do the timeout as a test to make sure it isn't timing related

lucien.knechtli03:07:55

ok tried the timeout and I'm still getting the error..

lucien.knechtli03:07:52

Also tried using the DOMContentLoaded event, I guess something about calling it as app.core.main() is creating the issue. weird

gadfly36104:07:20

Does calling<script> app.core.main(); </script>

mikethompson05:07:31

@lucien.knechtli: hard to tell, but the error seems to indicate that (.getElementById js/document "app") is failing to return a DOM element.

mikethompson05:07:53

For us to help you further, you have to come up with a minimal, complete example. Gist? repo?