Binding.scala icon indicating copy to clipboard operation
Binding.scala copied to clipboard

Example code in README.md doesn't work

Open mberndt123 opened this issue 7 years ago • 2 comments

Hey there,

I've had some trouble running the example code in README.md. More specifically, this code didn't work for me in Firefox 58:

@JSExport
def main(): Unit = {
  dom.render(document.body, table)
}

When I tried this, I found that it crashes, because document.body is null at that point. So I tried running the code in an event handler instead.

def main(): Unit = {
  window.addEventListener("load", { (_: Event) =>
    dom.render(document.body, table)
  })
}

And lo and behold, it worked!

mberndt123 avatar Feb 19 '18 01:02 mberndt123

Hi @mberndt123 , did you put SampleMain().main() inside of the <body>, as described in https://github.com/ThoughtWorksInc/Binding.scala#step-5-invoke-the-main-method-in-a-html-page ?

Atry avatar Feb 19 '18 11:02 Atry

Hi Atry,

Thanks for the response! I used scalaJSUseMainModuleInitializer := true, so I'm not invoking main manually at all, and I did put the <script> element into the <head> since I thought that's where they generally belong… Perhaps it's a good idea to add a hint about this particular pitfall, I might not be the only one to fall into it.

mberndt123 avatar Feb 19 '18 13:02 mberndt123