Commit 474fb9fb authored by Mathieu leclaire's avatar Mathieu leclaire

Add test with case class

parent 96f90045
......@@ -21,30 +21,43 @@ import JsRxTags._
object Client {
val helloValue = Var(0)
val caseClassValue = Var("empty")
@JSExport
def run() {
val submitButton = button("Click me")(
val submitButton1 = button("Click me")(
cursor := "pointer",
onclick := { () => Post[Api](_.hello(5)).foreach { i =>
helloValue() = helloValue() + i
onclick := { () =>
Post[Api](_.hello(5)).foreach { i =>
helloValue() = helloValue() + i
}
}
).render
val submitButton2 = button("Click me")(
cursor := "pointer",
onclick := { () =>
Post[Api](_.caseClass(MyCaseClass("Hello !"))).foreach { s =>
caseClassValue() = s
}
false
}
).render
Rx {
dom.document.body.appendChild(submitButton)
dom.document.body.appendChild(submitButton1)
dom.document.body.appendChild(submitButton2)
dom.document.body.appendChild(h1(helloValue).render)
dom.document.body.appendChild(h1(caseClassValue).render)
}
}
}
object Post extends autowire.Client[Web] {
override def callRequest(req: Request): Future[String] = {
val url = req.path.mkString("/")
println(" URL " + url)
dom.extensions.Ajax.post(
url = "http://localhost:8080/" + url,
data = upickle.write(req.args)
......
......@@ -11,8 +11,9 @@ object ScalaTraJSTagsWireRxBuild extends Build {
val ScalaVersion = "2.11.1"
val ScalatraVersion = "2.3.0"
lazy val shared = project.in(file("./shared"))
.settings(scalaVersion := ScalaVersion)
lazy val shared = project.in(file("./shared")).settings(
scalaVersion := ScalaVersion
).settings(jsManagerSettings: _*)
lazy val client = Project(
"client",
......@@ -29,7 +30,7 @@ object ScalaTraJSTagsWireRxBuild extends Build {
"org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6",
"org.scala-lang.modules.scalajs" %%% "scalajs-jquery" % "0.6"
),
jsCall := "Plot().run();",
jsCall := "Client().run();",
outputPath := "server/src/main/webapp/"
)
).dependsOn(shared)
......
......@@ -6,6 +6,9 @@ import scala.concurrent.ExecutionContext.Implicits.global
class ScalatraBootstrap extends LifeCycle {
override def init(context: ServletContext) {
//val serv = new MyScalatraServlet
// pluginROutes.foreach{serv.addRoute}
context.mount(new MyScalatraServlet, "/*")
}
}
......@@ -11,6 +11,7 @@ import scala.concurrent.Await
object Server extends Api {
def hello(a: Int) = a * 3
def caseClass(c: MyCaseClass) = c.oo
}
class MyScalatraServlet extends ServertestStack {
......@@ -27,6 +28,6 @@ class MyScalatraServlet extends ServertestStack {
autowire.Request(Seq(basePath) ++ multiParams("splat").head.split("/"),
upickle.read[Map[String, String]](request.body))
),Duration.Inf)
}
}
html
head
meta(charset="utf-8")
link(rel="stylesheet" href="css/styles.css")
link(rel="stylesheet" href="css/bootstrap.min.css")
script( type="text/javascript" src="js/d3.v3.min.js")
script( type="text/javascript" src="js/jquery-2.1.1.min.js")
script(type="text/javascript" src="js/bootstrap.min.js")
script(type="text/javascript" src="js/ui-fastopt.js")
script(type="text/javascript" src="js/ui-opt.js")
script(type="text/javascript" src="js/client-fastopt.js")
script(type="text/javascript" src="js/client-opt.js")
body
script="Plot().run();"
\ No newline at end of file
script="Client().run();"
\ No newline at end of file
package shared
import scala.annotation.ClassfileAnnotation
import scala.scalajs.js.annotation.JSExport
class Web extends ClassfileAnnotation
@JSExport
case class MyCaseClass(oo: String)
@Web
trait Api {
def hello(a: Int): Int
def caseClass(cc: MyCaseClass): String
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment