summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2015-02-04 05:31:48 -0800
committerLi Haoyi <haoyi@dropbox.com>2015-02-04 05:31:48 -0800
commitb094df4a6a6cf1bf7eeb36d842970aa8b3d94d5f (patch)
tree68db445a53fe7f2343a44773cb46d7e882dad7d1
parent49cf861b0a4e351e56ba797541d43cb1da345741 (diff)
downloadhands-on-scala-js-b094df4a6a6cf1bf7eeb36d842970aa8b3d94d5f.tar.gz
hands-on-scala-js-b094df4a6a6cf1bf7eeb36d842970aa8b3d94d5f.tar.bz2
hands-on-scala-js-b094df4a6a6cf1bf7eeb36d842970aa8b3d94d5f.zip
first attempt at updating things for 0.6.0
-rw-r--r--book/src/main/scala/book/Utils.scala15
-rw-r--r--book/src/main/scalatex/book/handson/CanvasApp.scalatex2
-rw-r--r--book/src/main/scalatex/book/handson/ClientServer.scalatex2
-rw-r--r--book/src/main/scalatex/book/handson/GettingStarted.scalatex10
-rw-r--r--book/src/main/scalatex/book/handson/WebPage.scalatex4
-rw-r--r--book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex2
-rw-r--r--build.sbt4
-rw-r--r--examples/crossBuilds/clientserver/build.sbt6
-rw-r--r--examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala2
-rw-r--r--examples/crossBuilds/clientserver2/client/src/main/scala/simple/Client.scala2
-rw-r--r--examples/crossBuilds/simple2/build.sbt15
-rw-r--r--examples/demos/build.sbt8
-rw-r--r--examples/demos/src/main/scala/Splash.scala4
-rw-r--r--examples/demos/src/main/scala/advanced/Async.scala11
-rw-r--r--examples/demos/src/main/scala/advanced/BasicRx.scala6
-rw-r--r--examples/demos/src/main/scala/advanced/Futures.scala21
-rw-r--r--examples/demos/src/main/scala/canvasapp/Clock.scala4
-rw-r--r--examples/demos/src/main/scala/canvasapp/FlappyLine.scala4
-rw-r--r--examples/demos/src/main/scala/canvasapp/ScratchPad.scala3
-rw-r--r--examples/demos/src/main/scala/scrollmenu/Controller.scala9
-rw-r--r--examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala21
-rw-r--r--examples/demos/src/main/scala/webpage/HelloWorld0.scala3
-rw-r--r--examples/demos/src/main/scala/webpage/HelloWorld1.scala3
-rw-r--r--examples/demos/src/main/scala/webpage/Inputs.scala3
-rw-r--r--examples/demos/src/main/scala/webpage/Search0.scala3
-rw-r--r--examples/demos/src/main/scala/webpage/Search1.scala4
-rw-r--r--examples/demos/src/main/scala/webpage/Weather0.scala4
-rw-r--r--examples/demos/src/main/scala/webpage/Weather1.scala6
-rw-r--r--examples/demos/src/main/scala/webpage/Weather2.scala5
-rw-r--r--examples/demos/src/main/scala/webpage/Weather3.scala5
-rw-r--r--examples/demos/src/main/scala/webpage/WeatherSearch.scala5
-rw-r--r--project/build.sbt4
32 files changed, 110 insertions, 90 deletions
diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala
index c14a6ba..c62f71f 100644
--- a/book/src/main/scala/book/Utils.scala
+++ b/book/src/main/scala/book/Utils.scala
@@ -35,14 +35,19 @@ object lnk{
a(name, href:=url)
}
object dom{
- def mdnThing(name: String) = lnk(name, "https://developer.mozilla.org/en-US/docs/Web/API/" + name)
+ def mdnThing(name: String, scalaJsName: String = null) = lnk(
+ Option(scalaJsName).getOrElse(name),
+ "https://developer.mozilla.org/en-US/docs/Web/API/" + name
+ )
def mdnEvent(name: String) = lnk(name, "https://developer.mozilla.org/en-US/docs/Web/Events/" + name)
val CanvasRenderingContext2D = mdnThing("CanvasRenderingContext2D")
- val HTMLCanvasElement = mdnThing("HTMLCanvasElement")
val Element = mdnThing("Element")
- val HTMLElement = mdnThing("HTMLElement")
- val HTMLInputElement = mdnThing("HTMLInputElement")
- val HTMLSpanElement = mdnThing("HTMLSpanElement")
+ object html{
+ val Canvas = mdnThing("HTMLCanvasElement", "html.Canvas")
+ val Element = mdnThing("HTMLElement", "html.Element")
+ val Input = mdnThing("HTMLInputElement", "html.Input")
+ val Span = mdnThing("HTMLSpanElement", "html.Span")
+ }
val XMLHttpRequest = mdnThing("XMLHttpRequest")
val getElementById = mdnThing("document.getElementById")
val setInterval = mdnThing("WindowTimers.setInterval")
diff --git a/book/src/main/scalatex/book/handson/CanvasApp.scalatex b/book/src/main/scalatex/book/handson/CanvasApp.scalatex
index ae97dee..e40b211 100644
--- a/book/src/main/scalatex/book/handson/CanvasApp.scalatex
+++ b/book/src/main/scalatex/book/handson/CanvasApp.scalatex
@@ -41,7 +41,7 @@
This code sets up the @lnk.dom.mousedown and @lnk.dom.mouseup events to keep track of whether or not the mouse has currently been clicked. It then draws black squares any time you move the mouse while the button is down. This lets you basically click-and-drag to draw pictures on the canvas. Try it out!
@p
- In general, you have access to all the DOM APIs through the @hl.scala{dom} package as well as through Javascript objects such as the @lnk.dom.HTMLCanvasElement. Setting the @code{onmouseXXX} callbacks is just one way of interacting with the DOM. With Scala.js, you also get a very handy autocomplete in the editor, which you can use to browse the various other APIs that are available for use:
+ In general, you have access to all the DOM APIs through the @hl.scala{dom} package as well as through Javascript objects such as the @lnk.dom.html.Canvas. Setting the @code{onmouseXXX} callbacks is just one way of interacting with the DOM. With Scala.js, you also get a very handy autocomplete in the editor, which you can use to browse the various other APIs that are available for use:
@img(src:="images/Dropdown.png", maxWidth:="100%")
diff --git a/book/src/main/scalatex/book/handson/ClientServer.scalatex b/book/src/main/scalatex/book/handson/ClientServer.scalatex
index 0d60192..5ee3dfe 100644
--- a/book/src/main/scalatex/book/handson/ClientServer.scalatex
+++ b/book/src/main/scalatex/book/handson/ClientServer.scalatex
@@ -103,7 +103,7 @@
@p
In both the client code and the server code, we made use of the same Scalatags HTML generation library. This is pretty neat: transferring rendering logic between client and server no longer means an annoying/messy rewrite! You can simply C&P the Scalatags snippet over. That means it's easy if you want to e.g. shift the logic from one side to the other in order to optimize for performance or time-to-load or other things.
@p
- One thing to take note of is that we're actually using subtly @i{different} implementations of Scalatags on both sides: on the server, we're importing from @hl.scala{scalatags.Text}, while on the client we're using @hl.scala{scalatags.JsDom}. The @hl.scala{Text} backend renders directly to Strings, and is available on both Scala-JVM and Scala.js. The @hl.scala{JsDom} backend, on the other hand, renders to @lnk.dom.HTMLElement-s which only exist on Scala.js. Thus while on the client you can do things like attach event listeners to the rendered @lnk.dom.HTMLElement objects, or checking their runtime @code{.value}, on the server you can't. And that's exactly what you want!
+ One thing to take note of is that we're actually using subtly @i{different} implementations of Scalatags on both sides: on the server, we're importing from @hl.scala{scalatags.Text}, while on the client we're using @hl.scala{scalatags.JsDom}. The @hl.scala{Text} backend renders directly to Strings, and is available on both Scala-JVM and Scala.js. The @hl.scala{JsDom} backend, on the other hand, renders to @lnk.dom.html.Element-s which only exist on Scala.js. Thus while on the client you can do things like attach event listeners to the rendered @lnk.dom.html.Element objects, or checking their runtime @code{.value}, on the server you can't. And that's exactly what you want!
@sect{Shared Code}
@p
diff --git a/book/src/main/scalatex/book/handson/GettingStarted.scalatex b/book/src/main/scalatex/book/handson/GettingStarted.scalatex
index c200f1e..5d4d299 100644
--- a/book/src/main/scalatex/book/handson/GettingStarted.scalatex
+++ b/book/src/main/scalatex/book/handson/GettingStarted.scalatex
@@ -115,7 +115,7 @@
This @hl.scala("@JSExport") annotation is used to tell Scala.js that you want this method to be visible and callable from Javascript. By default, Scala.js does @sect.ref("Fast Optimization", "dead code elimination") and removes any methods or classes which are not used. This is done to keep the compiled executables a reasonable size, since most projects use only a small fraction of e.g. the standard library. @hl.scala("@JSExport") is used to tell Scala.js that the @hl.scala{ScalaJSExample} object and its @hl.scala{def main} method are entry points to the program. Even if they aren't called anywhere internally, they are called externally by Javascript that the Scala.js compiler is not aware of, and should not be removed. In this case, we are going to call this method from Javascript to start the Scala.js program.
@p
- Apart from this annotation, @hl.scala{ScalaJSExample} is just a normal Scala @hl.scala{object}, and behaves like one in every way. Note that the main-method in this case takes a @lnk.dom.HTMLCanvasElement: your exported methods can have any signature, with arbitrary arity or types for parameters or the return value. This is in contrast to the main method on the JVM which always takes an @hl.scala{Array[String]} and returns @hl.scala{Unit}. In fact, there's nothing special about this method at all! It's like any other exported method, we just happen to attribute it the "main" entry point. It is entirely possible to define multiple exported classes and methods, and build a "library" using Scala.js of methods that are intended for external Javascript to use.
+ Apart from this annotation, @hl.scala{ScalaJSExample} is just a normal Scala @hl.scala{object}, and behaves like one in every way. Note that the main-method in this case takes a @lnk.dom.html.Canvas: your exported methods can have any signature, with arbitrary arity or types for parameters or the return value. This is in contrast to the main method on the JVM which always takes an @hl.scala{Array[String]} and returns @hl.scala{Unit}. In fact, there's nothing special about this method at all! It's like any other exported method, we just happen to attribute it the "main" entry point. It is entirely possible to define multiple exported classes and methods, and build a "library" using Scala.js of methods that are intended for external Javascript to use.
@hl.ref(example/"ScalaJSExample.scala", "val ctx", "var count")
@@ -123,7 +123,13 @@
Here we are retrieving a handle to the canvas we will draw on using @hl.scala{document.getElementById}, and from it we can get a @lnk.dom.CanvasRenderingContext2D which we actually use to draw on it.
@p
- We need to perform the @hl.scala{asInstanceOf} call because depending on what you pass to @hl.scala{getElementById} and @hl.scala{getContext}, you could be returned elements and contexts of different types. Hence we need to tell the compiler explicitly that we're expecting a @lnk.dom.HTMLCanvasElement and @lnk.dom.CanvasRenderingContext2D back from these methods for the strings we passed in.
+ We need to perform the @hl.scala{asInstanceOf} call because depending on what you pass to @hl.scala{getElementById} and @hl.scala{getContext}, you could be returned elements and contexts of different types. Hence we need to tell the compiler explicitly that we're expecting a @lnk.dom.html.Canvas and @lnk.dom.CanvasRenderingContext2D back from these methods for the strings we passed in.
+
+ @p
+ Note how the @lnk.dom.html.Canvas comes from the @hl.scala{html} namespace, while the @lnk.dom.CanvasRenderingContext2D comes from the @hl.scala{dom} namespace. Traditionally, these types are imported via their qualified names: e.g. @hl.scala{html.Canvas} rather than just @hl.scala{Canvas}.
+
+ @p
+ In general, @lnk("scala-js-dom", "http://scala-js.github.io/scala-js-dom/") provides @hl.scala{org.scalajs.dom.html} to access the HTML element types of the browser, an @hl.scala{org.scalajs.dom} to access other things. There are a number of other namespaces (@hl.scala{dom.svg}, @hl.scala{dom.idb}, etc.) accessible inside @hl.scala{org.scalajs.dom}: read the @lnk("scala-js-dom docs", "http://scala-js.github.io/scala-js-dom/") to learn more.
@hl.ref(example/"ScalaJSExample.scala", "def run", "dom.setInterval")
diff --git a/book/src/main/scalatex/book/handson/WebPage.scalatex b/book/src/main/scalatex/book/handson/WebPage.scalatex
index 03ed452..a7f754d 100644
--- a/book/src/main/scalatex/book/handson/WebPage.scalatex
+++ b/book/src/main/scalatex/book/handson/WebPage.scalatex
@@ -21,7 +21,7 @@
@BookData.example(div, "webpage.HelloWorld0().main")
@p
- Remember that we're now requiring a @hl.scala{dom.HTMLDivElement} instead of a @hl.scala{dom.HTMLCanvasElement} to be passed in when the Javascript calls @hl.javascript{webpage.HelloWorld0().main(...)}. If you're coming to this point from the previous chapter, you'll need to update the on-page Javascript's @hl.javascript{document.getElementById} to pick a @hl.html{<div>} rather than the @hl.html{<canvas>} we were using in the previous chapter.
+ Remember that we're now requiring a @hl.scala{html.Div} instead of a @hl.scala{html.Canvas} to be passed in when the Javascript calls @hl.javascript{webpage.HelloWorld0().main(...)}. If you're coming to this point from the previous chapter, you'll need to update the on-page Javascript's @hl.javascript{document.getElementById} to pick a @hl.html{<div>} rather than the @hl.html{<canvas>} we were using in the previous chapter.
@p
This approach works, as the above example shows, but has a couple of disadvantages:
@@ -66,7 +66,7 @@
@BookData.example(div(height:="150px"), "webpage.Inputs().main")
@p
- In Scalatags, you build up fragments of type @hl.scala{Frag} using functions like @hl.scala{div}, @hl.scala{h1}, etc., and call @hl.scala{.render} on it to turn it into a real @lnk.dom.Element. Different fragments render to different things: e.g. @hl.scala{input.render} gives you a @lnk.dom.HTMLInputElement, @hl.scala{span.render} gives you a @lnk.dom.HTMLSpanElement. You can then access the properties of these elements: adding callbacks, checking their value, anything you want.
+ In Scalatags, you build up fragments of type @hl.scala{Frag} using functions like @hl.scala{div}, @hl.scala{h1}, etc., and call @hl.scala{.render} on it to turn it into a real @lnk.dom.Element. Different fragments render to different things: e.g. @hl.scala{input.render} gives you a @lnk.dom.html.Input, @hl.scala{span.render} gives you a @lnk.dom.html.Span. You can then access the properties of these elements: adding callbacks, checking their value, anything you want.
@p
In this example, we render and @hl.scala{input} element and a @hl.scala{span}, wire up the input to set the value of the span whenever you press a key in the input, and then stuff both of them into a larger HTML fragment that forms the contents of our @hl.scala{target} element.
diff --git a/book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex b/book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex
index 5d91b62..ece6215 100644
--- a/book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex
+++ b/book/src/main/scalatex/book/indepth/CompilationPipeline.scalatex
@@ -134,7 +134,7 @@
@li
@b{Inlining}: under some circumstances, the optimizer inlines the implementation of methods at call sites. For example, it does so for all "small enough" methods. This typically reduces the code size by a small amount, but offers a several-times speedup of the generated code by inlining away much of the overhead from the abstractions (implicit-conversions, higher-order-functions, etc.) in Scala's standard library.
@li
- @b{Constant-folding}: due to inlining and other optimizations, some variables that could have arbitrary are known to contain a constant. These variables are replaced by their respective constants, which, in turn, can trigger more optimizations.
+ @b{Constant-folding}: due to inlining and other optimizations, some variables that could have arbitrary values are known to contain a constant. These variables are replaced by their respective constants, which, in turn, can trigger more optimizations.
@li
@b{Closure elimination}: probably one of the most important optimizations. When inlining a higher-order method such as @code{map}, the optimizer can in turn inline the anonymous function inside the body of the loop, effectively turning polymorphic dispatch with closures into bare-metal loops.
@p
diff --git a/build.sbt b/build.sbt
index 875b6de..0352d06 100644
--- a/build.sbt
+++ b/build.sbt
@@ -19,8 +19,8 @@ lazy val book = Project(
base = file("book")
).settings(sharedSettings ++ scalatex.SbtPlugin.projectSettings:_*).settings(
libraryDependencies ++= Seq(
- "com.scalatags" %% "scalatags" % "0.4.2",
- "com.lihaoyi" %%% "upickle" % "0.2.5",
+ "com.lihaoyi" %% "scalatags" % "0.4.5",
+ "com.lihaoyi" %%% "upickle" % "0.2.6",
"com.lihaoyi" %% "scalatex-site" % "0.1.1",
"com.lihaoyi" %% "ammonite" % "0.1.0"
),
diff --git a/examples/crossBuilds/clientserver/build.sbt b/examples/crossBuilds/clientserver/build.sbt
index e162ec4..94525ff 100644
--- a/examples/crossBuilds/clientserver/build.sbt
+++ b/examples/crossBuilds/clientserver/build.sbt
@@ -3,8 +3,8 @@ val sharedSettings = Seq(
unmanagedSourceDirectories in Compile +=
baseDirectory.value / "shared" / "main" / "scala",
libraryDependencies ++= Seq(
- "com.lihaoyi" %%% "scalatags" % "0.4.3-RC1",
- "com.lihaoyi" %%% "upickle" % "0.2.6-RC1"
+ "com.lihaoyi" %%% "scalatags" % "0.4.5",
+ "com.lihaoyi" %%% "upickle" % "0.2.7"
),
scalaVersion := "2.11.5"
)
@@ -14,7 +14,7 @@ lazy val client = project.in(file("client"))
.settings(sharedSettings:_*)
.settings(
libraryDependencies ++= Seq(
- "org.scala-js" %%% "scalajs-dom" % "0.7.0"
+ "org.scala-js" %%% "scalajs-dom" % "0.8.0"
)
)
diff --git a/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala b/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala
index 9b3eda1..63e891b 100644
--- a/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala
+++ b/examples/crossBuilds/clientserver/client/src/main/scala/simple/Client.scala
@@ -9,7 +9,7 @@ import scalajs.js.annotation.JSExport
@JSExport
object Client extends{
@JSExport
- def main(container: dom.HTMLDivElement) = {
+ def main(container: html.Div) = {
val inputBox = input.render
val outputBox = ul.render
def update() = Ajax.post("/ajax/list", inputBox.value).foreach{ xhr =>
diff --git a/examples/crossBuilds/clientserver2/client/src/main/scala/simple/Client.scala b/examples/crossBuilds/clientserver2/client/src/main/scala/simple/Client.scala
index 5aefb70..af3ea91 100644
--- a/examples/crossBuilds/clientserver2/client/src/main/scala/simple/Client.scala
+++ b/examples/crossBuilds/clientserver2/client/src/main/scala/simple/Client.scala
@@ -20,7 +20,7 @@ object Ajaxer extends autowire.Client[String, upickle.Reader, upickle.Writer]{
@JSExport
object Client extends{
@JSExport
- def main(container: dom.HTMLDivElement) = {
+ def main(container: html.Div) = {
val inputBox = input.render
val outputBox = ul.render
def update() = Ajaxer[Api].list(inputBox.value).call().foreach{ data =>
diff --git a/examples/crossBuilds/simple2/build.sbt b/examples/crossBuilds/simple2/build.sbt
index a20cf1d..eb22c41 100644
--- a/examples/crossBuilds/simple2/build.sbt
+++ b/examples/crossBuilds/simple2/build.sbt
@@ -1,13 +1,12 @@
-import utest.jsrunner.JsCrossBuild
-val cross = new JsCrossBuild(
+val cross = crossProject.settings(
// Shared settings here
-)
-
-lazy val js = cross.js.settings(
+).jsSettings(
// JS-specific settings here
-)
-
-lazy val jvm = cross.jvm.settings(
+).jvmSettings(
// JVM-specific settings here
)
+
+lazy val js = cross.js
+
+lazy val jvm = cross.jvm
diff --git a/examples/demos/build.sbt b/examples/demos/build.sbt
index 7b0d9e1..6a7b10c 100644
--- a/examples/demos/build.sbt
+++ b/examples/demos/build.sbt
@@ -10,12 +10,12 @@ scalaVersion := "2.11.4"
libraryDependencies += "com.lihaoyi" %% "acyclic" % "0.1.2" % "provided"
-libraryDependencies += "com.lihaoyi" %%% "upickle" % "0.2.6-RC1"
+libraryDependencies += "com.lihaoyi" %%% "upickle" % "0.2.6"
-libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.7.0"
+libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.8.0"
-libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.4.3-RC1"
+libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.4.5"
-libraryDependencies += "com.lihaoyi" %%% "scalarx" % "0.2.7-RC1"
+libraryDependencies += "com.lihaoyi" %%% "scalarx" % "0.2.7"
libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.2" \ No newline at end of file
diff --git a/examples/demos/src/main/scala/Splash.scala b/examples/demos/src/main/scala/Splash.scala
index 05cbbc2..c8b35db 100644
--- a/examples/demos/src/main/scala/Splash.scala
+++ b/examples/demos/src/main/scala/Splash.scala
@@ -1,13 +1,13 @@
import java.lang.Math._
import org.scalajs.dom
-
+import dom.html
import scalajs.js.annotation.JSExport
@JSExport
object Splash extends{
@JSExport
- def main(canvas: dom.HTMLCanvasElement) = {
+ def main(canvas: html.Canvas) = {
def clear() = {
canvas.width = canvas.parentElement.clientWidth
diff --git a/examples/demos/src/main/scala/advanced/Async.scala b/examples/demos/src/main/scala/advanced/Async.scala
index 7a7e5ff..3d70f27 100644
--- a/examples/demos/src/main/scala/advanced/Async.scala
+++ b/examples/demos/src/main/scala/advanced/Async.scala
@@ -1,6 +1,7 @@
package advanced
import org.scalajs.dom
+import dom.html
import concurrent._
import async.Async._
import scalajs.js.annotation.JSExport
@@ -8,7 +9,7 @@ import scalajs.concurrent.JSExecutionContext.Implicits.queue
@JSExport
object Async {
- def init(canvas: dom.HTMLCanvasElement) = {
+ def init(canvas: html.Canvas) = {
val renderer = canvas.getContext("2d")
.asInstanceOf[dom.CanvasRenderingContext2D]
@@ -22,7 +23,7 @@ object Async {
renderer
}
@JSExport
- def main(canvas: dom.HTMLCanvasElement) = {
+ def main(canvas: html.Canvas) = {
val renderer = init(canvas)
// async
def rect = canvas.getBoundingClientRect()
@@ -36,7 +37,7 @@ object Async {
new Channel[ME](canvas.onmousedown = _)
// Disabled due to scala-js#1469
- /*async{
+ async{
while(true){
val start = await(mousedown())
renderer.beginPath()
@@ -59,10 +60,10 @@ object Async {
await(mouseup())
renderer.clearRect(0, 0, 1000, 1000)
}
- }*/
+ }
}
@JSExport
- def main0(canvas: dom.HTMLCanvasElement) = {
+ def main0(canvas: html.Canvas) = {
val renderer = init(canvas)
// traditional
def rect = canvas.getBoundingClientRect()
diff --git a/examples/demos/src/main/scala/advanced/BasicRx.scala b/examples/demos/src/main/scala/advanced/BasicRx.scala
index 1c9a0c8..99ccb84 100644
--- a/examples/demos/src/main/scala/advanced/BasicRx.scala
+++ b/examples/demos/src/main/scala/advanced/BasicRx.scala
@@ -5,11 +5,11 @@ import scalajs.js
import scalajs.js.annotation.JSExport
import rx._
import scalatags.JsDom.all._
-
+import dom.html
@JSExport
object BasicRx {
@JSExport
- def main(container: dom.HTMLDivElement) = {
+ def main(container: html.Div) = {
val txt = Var("")
val numChars = Rx{txt().length}
val numWords = Rx{
@@ -39,7 +39,7 @@ object BasicRx {
)
}
@JSExport
- def main2(container: dom.HTMLDivElement) = {
+ def main2(container: html.Div) = {
val fruits = Seq(
"Apple", "Apricot", "Banana", "Cherry",
"Mango", "Mangosteen", "Mandarin",
diff --git a/examples/demos/src/main/scala/advanced/Futures.scala b/examples/demos/src/main/scala/advanced/Futures.scala
index d1142b9..995d768 100644
--- a/examples/demos/src/main/scala/advanced/Futures.scala
+++ b/examples/demos/src/main/scala/advanced/Futures.scala
@@ -1,8 +1,9 @@
package advanced
import org.scalajs.dom
+import dom.html
import org.scalajs.dom.XMLHttpRequest
-import org.scalajs.dom.extensions.{Ajax, KeyCode}
+import org.scalajs.dom.ext.{Ajax, KeyCode}
import scala.collection.mutable
import scala.concurrent.Future
import scalajs.js
@@ -11,8 +12,8 @@ import scalajs.js.annotation.JSExport
import scalajs.concurrent.JSExecutionContext.Implicits.runNow
@JSExport
object Futures {
- def main(container: dom.HTMLDivElement,
- handle: (Seq[String], dom.HTMLDivElement) => Unit) = {
+ def main(container: html.Div,
+ handle: (Seq[String], html.Div) => Unit) = {
val myInput = input(value:="London,Singapore,Berlin,New York").render
val output = div.render
myInput.onkeyup = (e: dom.KeyboardEvent) => {
@@ -42,7 +43,7 @@ object Futures {
.asInstanceOf[Double]
kelvins - 272.15
}
- def formatResults(output: dom.HTMLElement, results: Seq[(String, Double)]) = {
+ def formatResults(output: html.Element, results: Seq[(String, Double)]) = {
output.innerHTML = ""
output.appendChild(ul(
for((name, temp) <- results) yield li(
@@ -51,8 +52,8 @@ object Futures {
).render)
}
@JSExport
- def main0(container: dom.HTMLDivElement) = {
- def handle0(names: Seq[String], output: dom.HTMLDivElement) = {
+ def main0(container: html.Div) = {
+ def handle0(names: Seq[String], output: html.Div) = {
val results = mutable.Buffer.empty[(String, Double)]
for(name <- names){
val xhr = new XMLHttpRequest
@@ -70,8 +71,8 @@ object Futures {
main(container, handle0)
}
@JSExport
- def main1(container: dom.HTMLDivElement) = {
- def handle1(names: Seq[String], output: dom.HTMLDivElement) = {
+ def main1(container: html.Div) = {
+ def handle1(names: Seq[String], output: html.Div) = {
val results = mutable.Buffer.empty[(String, Double)]
for{
name <- names
@@ -87,8 +88,8 @@ object Futures {
main(container, handle1)
}
@JSExport
- def main2(container: dom.HTMLDivElement) = {
- def handle2(names: Seq[String], output: dom.HTMLDivElement) = {
+ def main2(container: html.Div) = {
+ def handle2(names: Seq[String], output: html.Div) = {
val futures = for(name <- names) yield{
Ajax.get(urlFor(name)).map( xhr =>
(name, parseTemp(xhr.responseText))
diff --git a/examples/demos/src/main/scala/canvasapp/Clock.scala b/examples/demos/src/main/scala/canvasapp/Clock.scala
index 793b84c..b64fcbe 100644
--- a/examples/demos/src/main/scala/canvasapp/Clock.scala
+++ b/examples/demos/src/main/scala/canvasapp/Clock.scala
@@ -2,13 +2,13 @@ package canvasapp
import org.scalajs.dom
-
+import dom.html
import scalajs.js
import scalajs.js.annotation.JSExport
@JSExport
object Clock extends{
@JSExport
- def main(canvas: dom.HTMLCanvasElement) = {
+ def main(canvas: html.Canvas) = {
/*setup*/
val renderer = canvas.getContext("2d")
.asInstanceOf[dom.CanvasRenderingContext2D]
diff --git a/examples/demos/src/main/scala/canvasapp/FlappyLine.scala b/examples/demos/src/main/scala/canvasapp/FlappyLine.scala
index af797f8..f05d68c 100644
--- a/examples/demos/src/main/scala/canvasapp/FlappyLine.scala
+++ b/examples/demos/src/main/scala/canvasapp/FlappyLine.scala
@@ -2,14 +2,14 @@ package canvasapp
import org.scalajs.dom
-
+import dom.html
import scalajs.js.annotation.JSExport
import scala.util.Random
@JSExport
object FlappyLine extends{
@JSExport
- def main(canvas: dom.HTMLCanvasElement) = {
+ def main(canvas: html.Canvas) = {
/*setup*/
val renderer = canvas.getContext("2d")
.asInstanceOf[dom.CanvasRenderingContext2D]
diff --git a/examples/demos/src/main/scala/canvasapp/ScratchPad.scala b/examples/demos/src/main/scala/canvasapp/ScratchPad.scala
index 65e873c..2d7daf1 100644
--- a/examples/demos/src/main/scala/canvasapp/ScratchPad.scala
+++ b/examples/demos/src/main/scala/canvasapp/ScratchPad.scala
@@ -4,11 +4,12 @@ package canvasapp
import org.scalajs.dom
import scalajs.js.annotation.JSExport
+import dom.html
@JSExport
object ScratchPad extends{
@JSExport
- def main(canvas: dom.HTMLCanvasElement) = {
+ def main(canvas: html.Canvas) = {
/*setup*/
val renderer = canvas.getContext("2d")
.asInstanceOf[dom.CanvasRenderingContext2D]
diff --git a/examples/demos/src/main/scala/scrollmenu/Controller.scala b/examples/demos/src/main/scala/scrollmenu/Controller.scala
index cfef7b0..b4e9b3b 100644
--- a/examples/demos/src/main/scala/scrollmenu/Controller.scala
+++ b/examples/demos/src/main/scala/scrollmenu/Controller.scala
@@ -1,7 +1,8 @@
package scrollmenu
import org.scalajs.dom
-import org.scalajs.dom.extensions._
+import dom.html
+import org.scalajs.dom.ext._
import scalajs.js
import scalajs.js.annotation.JSExport
@@ -23,7 +24,7 @@ object Controller{
val Seq(main, menu, layout, menuLink) = Seq(
"main", "menu", "layout", "menuLink"
- ).map(dom.document.getElementById(_).asInstanceOf[dom.HTMLElement])
+ ).map(dom.document.getElementById(_).asInstanceOf[html.Element])
val snippets = dom.document.getElementsByClassName("highlight-me")
@@ -73,8 +74,8 @@ object Controller{
menuLink.classList.toggle("active")
}
- main.onscroll = (e: dom.UIEvent) => updateScroll()
- updateScroll()
+// main.onscroll = (e: dom.UIEvent) => updateScroll()
+// updateScroll()
}
}
diff --git a/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala b/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala
index 9a64314..6419dc4 100644
--- a/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala
+++ b/examples/demos/src/main/scala/scrollmenu/ScrollSpy.scala
@@ -1,20 +1,21 @@
package scrollmenu
import org.scalajs.dom
-import org.scalajs.dom.extensions._
+import dom.html
+import org.scalajs.dom.ext._
import scalajs.js
import scalatags.JsDom.all._
case class Tree[T](value: T, children: Vector[Tree[T]])
-case class MenuNode(frag: dom.HTMLElement, id: String, start: Int, end: Int)
+case class MenuNode(frag: html.Element, id: String, start: Int, end: Int)
/**
* High performance scrollspy to work keep the left menu bar in sync.
* Lots of sketchy imperative code in order to maximize performance.
*/
class ScrollSpy(structure: Tree[String],
- main: dom.HTMLElement){
+ main: html.Element){
lazy val domTrees = {
var i = -1
def recurse(t: Tree[String], depth: Int): Tree[MenuNode] = {
@@ -44,9 +45,9 @@ class ScrollSpy(structure: Tree[String],
val domTrees = recurse(structure, 0)
domTrees
}
- def offset(el: dom.HTMLElement, parent: dom.HTMLElement): Double = {
+ def offset(el: html.Element, parent: html.Element): Double = {
if (el == parent) 0
- else el.offsetTop + offset(el.offsetParent.asInstanceOf[dom.HTMLElement], parent)
+ else el.offsetTop + offset(el.offsetParent.asInstanceOf[html.Element], parent)
}
lazy val headers = {
val menuItems = {
@@ -57,7 +58,7 @@ class ScrollSpy(structure: Tree[String],
}
js.Array(
- menuItems.map(name => dom.document.getElementById(Controller.munge(name)).asInstanceOf[dom.HTMLElement])
+ menuItems.map(name => dom.document.getElementById(Controller.munge(name)).asInstanceOf[html.Element])
.map((el) => () => offset(el, main)):_*
)
}
@@ -79,7 +80,7 @@ class ScrollSpy(structure: Tree[String],
def setFullHeight(mn: MenuNode) = {
mn.frag
.children(1)
- .asInstanceOf[dom.HTMLElement]
+ .asInstanceOf[html.Element]
.style
.maxHeight = (mn.end - mn.start + 1) * 44 + "px"
}
@@ -88,7 +89,7 @@ class ScrollSpy(structure: Tree[String],
def apply(): Unit = {
if (!scrolling) {
scrolling = true
- scrollTop = main.scrollTop
+ scrollTop = main.scrollTop.toInt
dom.setTimeout({() =>
scrolling = false
if (scrollTop == main.scrollTop) start()
@@ -140,7 +141,7 @@ class ScrollSpy(structure: Tree[String],
} walkHide(child)
val size = walkTree(rest) + children.length
- mn.frag.children(1).asInstanceOf[dom.HTMLElement].style.maxHeight =
+ mn.frag.children(1).asInstanceOf[html.Element].style.maxHeight =
if (!open) size * 44 + "px" else "none"
size
}
@@ -151,7 +152,7 @@ class ScrollSpy(structure: Tree[String],
frag.children(0).classList.remove("pure-menu-selected")
frag.classList.add("hide")
- frag.children(1).asInstanceOf[dom.HTMLElement].style.maxHeight =
+ frag.children(1).asInstanceOf[html.Element].style.maxHeight =
if (!open) "0px" else "none"
if (tree.value.start < winItem.start) frag.classList.add("selected")
diff --git a/examples/demos/src/main/scala/webpage/HelloWorld0.scala b/examples/demos/src/main/scala/webpage/HelloWorld0.scala
index 4ec7d30..e2fabec 100644
--- a/examples/demos/src/main/scala/webpage/HelloWorld0.scala
+++ b/examples/demos/src/main/scala/webpage/HelloWorld0.scala
@@ -1,10 +1,11 @@
package webpage
import org.scalajs.dom
+import dom.html
import scalajs.js.annotation.JSExport
@JSExport
object HelloWorld0 extends{
@JSExport
- def main(target: dom.HTMLDivElement) ={
+ def main(target: html.Div) ={
val (f, d) = ("fox", "dog")
target.innerHTML = s"""
<div>
diff --git a/examples/demos/src/main/scala/webpage/HelloWorld1.scala b/examples/demos/src/main/scala/webpage/HelloWorld1.scala
index f897c98..86d75f4 100644
--- a/examples/demos/src/main/scala/webpage/HelloWorld1.scala
+++ b/examples/demos/src/main/scala/webpage/HelloWorld1.scala
@@ -1,11 +1,12 @@
package webpage
import org.scalajs.dom
+import dom.html
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
@JSExport
object HelloWorld1 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
+ def main(target: html.Div) = {
val (animalA, animalB) = ("fox", "dog")
target.appendChild(
div(
diff --git a/examples/demos/src/main/scala/webpage/Inputs.scala b/examples/demos/src/main/scala/webpage/Inputs.scala
index 0354d6d..fc8d37d 100644
--- a/examples/demos/src/main/scala/webpage/Inputs.scala
+++ b/examples/demos/src/main/scala/webpage/Inputs.scala
@@ -1,13 +1,14 @@
package webpage
import org.scalajs.dom
+import dom.html
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
@JSExport
object Inputs extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
+ def main(target: html.Div) = {
val box = input(
`type`:="text",
placeholder:="Type here!"
diff --git a/examples/demos/src/main/scala/webpage/Search0.scala b/examples/demos/src/main/scala/webpage/Search0.scala
index d44dc34..89c2449 100644
--- a/examples/demos/src/main/scala/webpage/Search0.scala
+++ b/examples/demos/src/main/scala/webpage/Search0.scala
@@ -1,13 +1,14 @@
package webpage
import org.scalajs.dom
+import dom.html
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
@JSExport
object Search0 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
+ def main(target: html.Div) = {
val listings = Seq(
"Apple", "Apricot", "Banana", "Cherry",
"Mango", "Mangosteen", "Mandarin",
diff --git a/examples/demos/src/main/scala/webpage/Search1.scala b/examples/demos/src/main/scala/webpage/Search1.scala
index 9a37ca9..dc5ff7b 100644
--- a/examples/demos/src/main/scala/webpage/Search1.scala
+++ b/examples/demos/src/main/scala/webpage/Search1.scala
@@ -3,11 +3,11 @@ package webpage
import org.scalajs.dom
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
-
+import dom.html
@JSExport
object Search1 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
+ def main(target: html.Div) = {
val listings = Seq(
"Apple", "Apricot", "Banana", "Cherry",
"Mango", "Mangosteen", "Mandarin",
diff --git a/examples/demos/src/main/scala/webpage/Weather0.scala b/examples/demos/src/main/scala/webpage/Weather0.scala
index 2bf4666..a650f4e 100644
--- a/examples/demos/src/main/scala/webpage/Weather0.scala
+++ b/examples/demos/src/main/scala/webpage/Weather0.scala
@@ -5,11 +5,11 @@ import org.scalajs.dom.{Node, Element}
import scalajs.js
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
-
+import dom.html
@JSExport
object Weather0 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
+ def main(target: html.Div) = {
val xhr = new dom.XMLHttpRequest()
xhr.open("GET",
"http://api.openweathermap.org/" +
diff --git a/examples/demos/src/main/scala/webpage/Weather1.scala b/examples/demos/src/main/scala/webpage/Weather1.scala
index 1d61678..3b4cbb5 100644
--- a/examples/demos/src/main/scala/webpage/Weather1.scala
+++ b/examples/demos/src/main/scala/webpage/Weather1.scala
@@ -5,12 +5,12 @@ import org.scalajs.dom.{Node, Element}
import scalajs.js
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
-
+import dom.html
@JSExport
object Weather1 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
- import dom.extensions._
+ def main(target: html.Div) = {
+ import dom.ext._
import scala.scalajs
.concurrent
.JSExecutionContext
diff --git a/examples/demos/src/main/scala/webpage/Weather2.scala b/examples/demos/src/main/scala/webpage/Weather2.scala
index bf908e3..0396a9d 100644
--- a/examples/demos/src/main/scala/webpage/Weather2.scala
+++ b/examples/demos/src/main/scala/webpage/Weather2.scala
@@ -5,12 +5,13 @@ import org.scalajs.dom.{Node, Element}
import scalajs.js
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
+import dom.html
@JSExport
object Weather2 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
- import dom.extensions._
+ def main(target: html.Div) = {
+ import dom.ext._
import scala.scalajs
.concurrent
.JSExecutionContext
diff --git a/examples/demos/src/main/scala/webpage/Weather3.scala b/examples/demos/src/main/scala/webpage/Weather3.scala
index 3a7a2ac..bbe5dcc 100644
--- a/examples/demos/src/main/scala/webpage/Weather3.scala
+++ b/examples/demos/src/main/scala/webpage/Weather3.scala
@@ -5,12 +5,13 @@ import org.scalajs.dom.{Node, Element}
import scalajs.js
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
+import dom.html
@JSExport
object Weather3 extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
- import dom.extensions._
+ def main(target: html.Div) = {
+ import dom.ext._
import scala.scalajs
.concurrent
.JSExecutionContext
diff --git a/examples/demos/src/main/scala/webpage/WeatherSearch.scala b/examples/demos/src/main/scala/webpage/WeatherSearch.scala
index de8d1e2..951fa46 100644
--- a/examples/demos/src/main/scala/webpage/WeatherSearch.scala
+++ b/examples/demos/src/main/scala/webpage/WeatherSearch.scala
@@ -1,16 +1,17 @@
package webpage
import org.scalajs.dom
-import dom.extensions._
+import dom.ext._
import scalajs.concurrent.JSExecutionContext.Implicits.runNow
import scalajs.js
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
+import dom.html
@JSExport
object WeatherSearch extends{
@JSExport
- def main(target: dom.HTMLDivElement) = {
+ def main(target: html.Div) = {
lazy val box = input(
`type`:="text",
diff --git a/project/build.sbt b/project/build.sbt
index 43b4d9b..b1cfc53 100644
--- a/project/build.sbt
+++ b/project/build.sbt
@@ -1,6 +1,4 @@
-addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-RC2")
-
-addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.5-RC1")
+addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")