play-scalajs-showcase icon indicating copy to clipboard operation
play-scalajs-showcase copied to clipboard

Confused about Scalatags/ScalaJS

Open JohnReedLOL opened this issue 8 years ago • 1 comments

I'm using your example and I'm confused about Scalatags/ScalaJS. For the Play Twirl templates, I understand that I can trace them back to a call to something like:

Ok(views.html.index(SharedMessages.itWorks))

I know if I see views.html.index, then there must be a twirl template named "index.scala.html" inside the "views" directory.

Where are the Scalatags being called? How are they generating HTML. Are they actually generating the HTML or is it like Javascript that is manipulating the DOM to make HTML?

JohnReedLOL avatar Apr 05 '16 05:04 JohnReedLOL

What you understand about Twirl template is correct. You can find Twirl templates in https://github.com/hussachai/play-scalajs-showcase/tree/master/example-server/app/views You can see that in each Twirl template, there is a javascript call of a main function. Scalatags and other Scalajs code will be compiled into module-fastopt.js, module-jsdeps.js, module-launcher.js, and module-fastopt.js.map. Those files will be included by playscalajs plugin by calling @playscalajs.html.scripts("exampleClient", "/assets") HTML elements will be generated by DOM API via Scalatag and Scalajs-DOM.

hussachai avatar Apr 06 '16 02:04 hussachai