Skip to content

Commit

Permalink
clientserver examples now work with crossProject
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Haoyi committed Feb 4, 2015
1 parent b094df4 commit 3e92267
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package simple
import scalatags.JsDom.all._
import scalajs.concurrent.JSExecutionContext.Implicits.runNow
import org.scalajs.dom
import dom.extensions.Ajax
import dom.html
import dom.ext.Ajax
import scalajs.js.annotation.JSExport

@JSExport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Page{
val skeleton =
html(
head(
script(src:="/client-fastopt.js"),
script(src:="/appjs-fastopt.js"),
link(
rel:="stylesheet",
href:="https://cdnjs.cloudflare.com/ajax/libs/pure/0.5.0/pure-min.css"
Expand Down
27 changes: 11 additions & 16 deletions examples/crossBuilds/clientserver/build.sbt
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import NativePackagerKeys._
val sharedSettings = Seq(

val app = crossProject.settings(
unmanagedSourceDirectories in Compile +=
baseDirectory.value / "shared" / "main" / "scala",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "scalatags" % "0.4.5",
"com.lihaoyi" %%% "upickle" % "0.2.7"
"com.lihaoyi" %%% "upickle" % "0.2.6"
),
scalaVersion := "2.11.5"
)

lazy val client = project.in(file("client"))
.enablePlugins(ScalaJSPlugin)
.settings(sharedSettings:_*)
.settings(
).jsSettings(
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.8.0"
)
)

lazy val server = project.in(file("server"))
.settings(sharedSettings:_*)
.settings(packageArchetype.java_application:_*)
.settings(
).jvmSettings(
libraryDependencies ++= Seq(
"io.spray" %% "spray-can" % "1.3.2",
"io.spray" %% "spray-routing" % "1.3.2",
"com.typesafe.akka" %% "akka-actor" % "2.3.6"
),
(resources in Compile) += (fastOptJS in (client, Compile)).value.data
)
)

lazy val appJS = app.js
lazy val appJVM = app.jvm.settings(
(resources in Compile) += (fastOptJS in (appJS, Compile)).value.data
)

2 changes: 1 addition & 1 deletion examples/crossBuilds/clientserver/project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*project/build.sbt*/
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-RC2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.4")
1 change: 0 additions & 1 deletion examples/crossBuilds/clientserver/server/shared

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package simple
import scalatags.JsDom.all._
import org.scalajs.dom
import dom.html
import scalajs.js.annotation.JSExport
import scalajs.concurrent.JSExecutionContext.Implicits.runNow
import autowire._

object Ajaxer extends autowire.Client[String, upickle.Reader, upickle.Writer]{
override def doCall(req: Request) = {
dom.extensions.Ajax.post(
dom.ext.Ajax.post(
url = "/ajax/" + req.path.mkString("/"),
data = upickle.write(req.args)
).map(_.responseText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Page{
val skeleton =
html(
head(
script(src:="/client-fastopt.js"),
script(src:="/appjs-fastopt.js"),
link(
rel:="stylesheet",
href:="http://yui.yahooapis.com/pure/0.5.0/pure-min.css"
Expand Down
40 changes: 18 additions & 22 deletions examples/crossBuilds/clientserver2/build.sbt
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
val sharedSettings = Seq(
val app = crossProject.settings(
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" %%% "autowire" % "0.2.4-RC1"
"com.lihaoyi" %%% "scalatags" % "0.4.5",
"com.lihaoyi" %%% "upickle" % "0.2.6",
"com.lihaoyi" %%% "autowire" % "0.2.4"
),
scalaVersion := "2.11.5"
)

lazy val client = project.in(file("client"))
.enablePlugins(ScalaJSPlugin)
.settings(sharedSettings:_*)
.settings(
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.7.0"
).jsSettings(
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.8.0"
)
).jvmSettings(
libraryDependencies ++= Seq(
"io.spray" %% "spray-can" % "1.3.2",
"io.spray" %% "spray-routing" % "1.3.2",
"com.typesafe.akka" %% "akka-actor" % "2.3.6"
)
)
)

lazy val server = project.in(file("server"))
.settings(sharedSettings:_*)
.settings(
libraryDependencies ++= Seq(
"io.spray" %% "spray-can" % "1.3.2",
"io.spray" %% "spray-routing" % "1.3.2",
"com.typesafe.akka" %% "akka-actor" % "2.3.6"
),
(resources in Compile) += (fastOptJS in (client, Compile)).value.data
lazy val appJS = app.js
lazy val appJVM = app.jvm.settings(
(resources in Compile) += (fastOptJS in (appJS, Compile)).value.data
)


2 changes: 1 addition & 1 deletion examples/crossBuilds/clientserver2/project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*project/build.sbt*/
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-RC2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")

1 change: 0 additions & 1 deletion examples/crossBuilds/clientserver2/server/shared

This file was deleted.

15 changes: 9 additions & 6 deletions examples/crossBuilds/simple/build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
val sharedSettings = Seq(
unmanagedSourceDirectories in Compile +=
baseDirectory.value / "shared" / "main" / "scala"

val cross = crossProject.settings(
// Shared settings here
).jsSettings(
// JS-specific settings here
).jvmSettings(
// JVM-specific settings here
)

lazy val js = project.in(file("js")).enablePlugins(ScalaJSPlugin)
.settings(sharedSettings:_*)
lazy val js = cross.js

lazy val jvm = project.in(file("jvm")).settings(sharedSettings:_*)
lazy val jvm = cross.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
package simple
import scalajs.js

object Platform extends js.JSApp{
object Platform{
def format(ts: Long) = {
new js.Date(ts).toISOString()
}
def main() = {
val times = Seq(
0L,
1L << 32
)
println("Running on JS! " + 1.0d)
println(Simple.formatTimes(times))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//jvm/src/main/scala/simple/Platform.scala
package simple
import java.text.SimpleDateFormat
import java.util.{TimeZone, Locale}
import java.util.TimeZone

object Platform{
def format(ts: Long) = {
Expand All @@ -11,12 +11,4 @@ object Platform{
fmt.setTimeZone(TimeZone.getTimeZone("UTC"))
fmt.format(new java.util.Date(ts))
}
def main(args: Array[String]) = {
val times = Seq(
0L,
1L << 32
)
println("Running on JVM! " + 1.0d)
println(Simple.formatTimes(times))
}
}
2 changes: 1 addition & 1 deletion examples/crossBuilds/simple/project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*project/build.sbt*/
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-RC2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")
12 changes: 0 additions & 12 deletions examples/crossBuilds/simple2/build.sbt

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion examples/crossBuilds/simple2/jvm/shared

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion examples/crossBuilds/simple2/project/build.properties

This file was deleted.

4 changes: 0 additions & 4 deletions examples/crossBuilds/simple2/project/build.sbt

This file was deleted.

4 changes: 2 additions & 2 deletions examples/demos/src/main/scala/scrollmenu/Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ object Controller{
menuLink.classList.toggle("active")
}

// main.onscroll = (e: dom.UIEvent) => updateScroll()
// updateScroll()
main.onscroll = (e: dom.UIEvent) => updateScroll()
updateScroll()

}
}

0 comments on commit 3e92267

Please sign in to comment.