Commit f88c6982 authored by Mathieu leclaire's avatar Mathieu leclaire

to autowire and upickle 0.2.1

parent 1b2eda53
......@@ -29,7 +29,7 @@ object Client {
val submitButton1 = button("Click me")(
cursor := "pointer",
onclick := { () =>
Post(_.hello(5)).foreach { i =>
Post[Api].hello(5).call().foreach { i =>
helloValue() = helloValue() + i
}
}
......@@ -38,17 +38,18 @@ object Client {
val submitButton2 = button("Click me")(
cursor := "pointer",
onclick := { () =>
Post(_.caseClass).foreach { s =>
Post[Api].caseClass.call().foreach { s =>
caseClassValue() = s.hello
}
false
}
).render
dom.document.body.appendChild(submitButton1)
dom.document.body.appendChild(submitButton2)
dom.document.body.appendChild(submitButton1)
dom.document.body.appendChild(submitButton2)
Rx {
println("RX " + helloValue)
dom.document.body.appendChild(h1(helloValue).render)
dom.document.body.appendChild(h1(caseClassValue).render)
}
......@@ -56,9 +57,9 @@ object Client {
}
object Post extends autowire.Client[Api] {
object Post extends autowire.Client[String, upickle.Reader, upickle.Writer] {
override def callRequest(req: Request): Future[String] = {
override def doCall(req: Request): Future[String] = {
val url = req.path.mkString("/")
dom.extensions.Ajax.post(
url = "http://localhost:8080/" + url,
......@@ -67,4 +68,8 @@ object Post extends autowire.Client[Api] {
_.responseText
}
}
def read[Result: upickle.Reader](p: String) = upickle.read[Result](p)
def write[Result: upickle.Writer](r: Result) = upickle.write(r)
}
......@@ -28,8 +28,8 @@ object ScalaTraJSTagsWireRxBuild extends Build {
scalaVersion := ScalaVersion,
resolvers ++= Resolvers,
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "autowire" % "0.1.4",
"com.lihaoyi" %%% "upickle" % "0.2.1",
"com.lihaoyi" %%% "autowire" % "0.2.2",
"com.lihaoyi" %%% "upickle" % "0.2.2",
"com.scalatags" %%% "scalatags" % "0.4.0",
"com.scalarx" %%% "scalarx" % "0.2.6",
"org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6",
......@@ -50,10 +50,9 @@ object ScalaTraJSTagsWireRxBuild extends Build {
scalaVersion := ScalaVersion,
resolvers ++= Resolvers,
libraryDependencies ++= Seq(
"com.lihaoyi" %% "autowire" % "0.1.4",
"com.lihaoyi" %%% "upickle" % "0.2.1",
"com.lihaoyi" %% "autowire" % "0.2.1",
"com.lihaoyi" %% "upickle" % "0.2.1",
"com.scalatags" %%% "scalatags" % "0.4.0",
"org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6",
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.0.12" % "runtime",
......
......@@ -9,6 +9,6 @@ class ScalatraBootstrap extends LifeCycle {
//val serv = new MyScalatraServlet
// pluginROutes.foreach{serv.addRoute}
context.mount(new MyScalatraServlet, "/*")
context.mount(new Server, "/*")
}
}
......@@ -13,13 +13,18 @@ import scala.concurrent.Await
import scalatags.Text.all._
import scalatags.Text.{all => tags}
object Server extends Api {
object AutowireServer extends autowire.Server[String, upickle.Reader, upickle.Writer]{
def read[Result: upickle.Reader](p: String) = upickle.read[Result](p)
def write[Result: upickle.Writer](r: Result) = upickle.write(r)
}
object ApiImpl extends Api {
def hello(a: Int) = a * 3
def caseClass = MyCaseClass("Hello !")
}
class MyScalatraServlet extends ScalatraServlet {
class Server extends ScalatraServlet {
val basePath = "shared"
......@@ -37,8 +42,8 @@ class MyScalatraServlet extends ScalatraServlet {
}
post(s"/$basePath/*") {
Await.result(autowire.Macros.route[Api](Server)(
autowire.Request(Seq(basePath) ++ multiParams("splat").head.split("/"),
Await.result(AutowireServer.route[Api](ApiImpl)(
autowire.Core.Request(Seq(basePath) ++ multiParams("splat").head.split("/"),
upickle.read[Map[String, String]](request.body))
), Duration.Inf)
}
......
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