Skip to content

Update for recent tooling versions - Scala 3 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Step 5: Setup the UI in Scala.js
  • Loading branch information
sjrd authored and OndrejSpanel committed Mar 24, 2024
commit 66cb9a642f58aecd2ca1fcff8c138e840d5c7f73
4 changes: 0 additions & 4 deletions scalajs-tutorial-fastopt.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<title>The Scala.js Tutorial</title>
</head>
<body>
<button id="click-me-button" type="button" onclick="addClickedMessage()">
Click me!
</button>

<!-- Include Scala.js compiled code -->
<script type="text/javascript" src="./target/scala-2.13/scala-js-tutorial-fastopt/main.js"></script>
</body>
Expand Down
16 changes: 13 additions & 3 deletions src/main/scala/tutorial/webapp/TutorialApp.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package tutorial.webapp

import scala.scalajs.js.annotation.JSExportTopLevel

import org.scalajs.dom
import org.scalajs.dom.document

object TutorialApp {
def main(args: Array[String]): Unit = {
document.addEventListener("DOMContentLoaded", { (e: dom.Event) =>
setupUI()
})
}

def setupUI(): Unit = {
val button = document.createElement("button")
button.textContent = "Click me!"
button.addEventListener("click", { (e: dom.MouseEvent) =>
addClickedMessage()
})
document.body.appendChild(button)

appendPar(document.body, "Hello World")
}

Expand All @@ -16,7 +27,6 @@ object TutorialApp {
targetNode.appendChild(parNode)
}

@JSExportTopLevel("addClickedMessage")
def addClickedMessage(): Unit = {
appendPar(document.body, "You clicked the button!")
}
Expand Down