Skip to content

Commit 371e847

Browse files
author
Starzu
committed
Demo upgrade
1 parent ab0e793 commit 371e847

30 files changed

+126
-187
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ before_script:
2424
script:
2525
- sbt ++$TRAVIS_SCALA_VERSION test
2626
- sbt ++$TRAVIS_SCALA_VERSION publishLocal
27-
- cd example && sbt ++$TRAVIS_SCALA_VERSION compile
27+
- cd example && sbt ++$TRAVIS_SCALA_VERSION compile fullOptJS

example/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### How to use?
2+
3+
Run `sbt fastOptJS` or `sbt fullOptJS` to compile this demo. You can find all generated files
4+
in the `generated` directory. Open `index.html` in your browser.

example/build.sbt

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,61 @@
1-
import UdashBuild._
2-
import Dependencies._
3-
41
name := "jquery-demo"
52

6-
version in ThisBuild := "1.1.0"
7-
scalaVersion in ThisBuild := "2.12.2"
8-
organization in ThisBuild := "io.udash"
9-
crossPaths in ThisBuild := false
10-
scalacOptions in ThisBuild ++= Seq(
11-
"-feature",
12-
"-deprecation",
13-
"-unchecked",
14-
"-language:implicitConversions",
15-
"-language:existentials",
16-
"-language:dynamics",
17-
"-Xfuture",
18-
"-Xfatal-warnings"
19-
)
3+
inThisBuild(Seq(
4+
version := "1.2.0",
5+
organization := "io.udash",
6+
scalaVersion := "2.12.6",
7+
scalacOptions ++= Seq(
8+
"-feature",
9+
"-deprecation",
10+
"-unchecked",
11+
"-language:implicitConversions",
12+
"-language:existentials",
13+
"-language:dynamics",
14+
"-language:postfixOps",
15+
"-Xfuture",
16+
"-Xfatal-warnings",
17+
"-Xlint:_",
18+
),
19+
scalacOptions ++= {
20+
if (CrossVersion.partialVersion((`jquery-demo` / scalaVersion).value).contains((2, 12))) Seq(
21+
"-Ywarn-unused:_,-explicits,-implicits",
22+
"-Ybackend-parallelism", "4",
23+
"-Ycache-plugin-class-loader:last-modified",
24+
"-Ycache-macro-class-loader:last-modified"
25+
) else Seq.empty
26+
},
27+
))
2028

2129
val generatedDir = file("generated")
30+
val copyAssets = taskKey[Unit]("Copies all assets to the target directory.")
2231
val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin)
2332
.settings(
24-
libraryDependencies ++= deps.value,
33+
libraryDependencies ++= Dependencies.deps.value,
2534

2635
/* move these files out of target/. */
27-
crossTarget in (Compile, fullOptJS) := generatedDir,
28-
crossTarget in (Compile, fastOptJS) := generatedDir,
29-
crossTarget in (Compile, packageJSDependencies) := generatedDir,
30-
crossTarget in (Compile, packageMinifiedJSDependencies) := generatedDir,
36+
Compile / fullOptJS / crossTarget := generatedDir,
37+
Compile / fastOptJS / crossTarget := generatedDir,
38+
Compile / packageJSDependencies / crossTarget := generatedDir,
39+
Compile / packageMinifiedJSDependencies / crossTarget := generatedDir,
3140

32-
compile := (compile in Compile).dependsOn(compileStatics).value,
33-
compileStatics := {
34-
compileStaticsForRelease.value
35-
(crossTarget.value / StaticFilesDir).***.get
36-
},
41+
Compile / fastOptJS := (Compile / fastOptJS).dependsOn(copyAssets).value,
42+
Compile / fullOptJS := (Compile / fullOptJS).dependsOn(copyAssets).value,
3743

3844
scalaJSUseMainModuleInitializer := true,
3945

40-
artifactPath in(Compile, fastOptJS) :=
41-
(crossTarget in(Compile, fastOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl-fast.js",
42-
artifactPath in(Compile, fullOptJS) :=
43-
(crossTarget in(Compile, fullOptJS)).value / StaticFilesDir / WebContent / "scripts" / "frontend-impl.js",
44-
artifactPath in(Compile, packageJSDependencies) :=
45-
(crossTarget in(Compile, packageJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps-fast.js",
46-
artifactPath in(Compile, packageMinifiedJSDependencies) :=
47-
(crossTarget in(Compile, packageMinifiedJSDependencies)).value / StaticFilesDir / WebContent / "scripts" / "frontend-deps.js"
46+
copyAssets := {
47+
IO.copyFile(
48+
sourceDirectory.value / "main/assets/index.html",
49+
generatedDir / "index.html"
50+
)
51+
},
52+
53+
Compile / fastOptJS / artifactPath :=
54+
(Compile / fastOptJS / crossTarget).value / "scripts" / "frontend-impl.js",
55+
Compile / fullOptJS / artifactPath :=
56+
(Compile / fullOptJS / crossTarget).value / "scripts" / "frontend-impl.js",
57+
Compile / packageJSDependencies / artifactPath :=
58+
(Compile / packageJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js",
59+
Compile / packageMinifiedJSDependencies / artifactPath :=
60+
(Compile / packageMinifiedJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js"
4861
)

example/project/Dependencies.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
22
import sbt._
33

44
object Dependencies {
5-
val udashCoreVersion = "0.5.0"
6-
val udashJQueryVersion = "1.1.0"
5+
val udashCoreVersion = "0.6.1"
6+
val udashJQueryVersion = "1.2.0"
77

88
val deps = Def.setting(Seq[ModuleID](
99
"io.udash" %%% "udash-core-frontend" % udashCoreVersion,

example/project/UdashBuild.scala

Lines changed: 0 additions & 36 deletions
This file was deleted.

example/project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 0.13.15
1+
sbt.version = 1.1.4

example/project/plugins.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
logLevel := Level.Warn
2-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.18")
2+
3+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.22")

example/src/main/assets/index.dev.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/src/main/assets/index.prod.html renamed to example/src/main/assets/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<script src="scripts/frontend-deps.js"></script>
88
<script src="scripts/frontend-impl.js"></script>
9-
109
</head>
1110
<body>
1211
<div id="application"></div>

example/src/main/scala/io/udash/demos/jquery/RoutingRegistryDef.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.udash.demos.jquery
22

33
import io.udash._
4-
import io.udash.utils.Bidirectional
54

65
class RoutingRegistryDef extends RoutingRegistry[RoutingState] {
76
def matchUrl(url: Url): RoutingState =
@@ -10,7 +9,7 @@ class RoutingRegistryDef extends RoutingRegistry[RoutingState] {
109
def matchState(state: RoutingState): Url =
1110
Url(state2Url.apply(state))
1211

13-
private val (url2State, state2Url) = Bidirectional[String, RoutingState] {
12+
private val (url2State, state2Url) = bidirectional {
1413
case "" => IndexState
1514
case "/add" => AddState
1615
case "/addBack" => AddBackState

example/src/main/scala/io/udash/demos/jquery/StatesToViewPresenterDef.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import io.udash._
44
import io.udash.demos.jquery.views.functions._
55
import io.udash.demos.jquery.views.{ErrorViewPresenter, IndexViewPresenter, RootViewPresenter}
66

7-
class StatesToViewPresenterDef extends ViewPresenterRegistry[RoutingState] {
8-
def matchStateToResolver(state: RoutingState): ViewPresenter[_ <: RoutingState] = state match {
7+
class StatesToViewPresenterDef extends ViewFactoryRegistry[RoutingState] {
8+
def matchStateToResolver(state: RoutingState): ViewFactory[_ <: RoutingState] = state match {
99
case RootState => RootViewPresenter
1010
case IndexState => IndexViewPresenter
1111
case AddState => AddViewPresenter

example/src/main/scala/io/udash/demos/jquery/init.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ package io.udash.demos.jquery
33
import io.udash._
44
import io.udash.wrappers.jquery._
55
import org.scalajs.dom
6-
import org.scalajs.dom.{Element, document}
6+
import org.scalajs.dom.Element
77

8-
import scala.scalajs.js.JSApp
98
import scala.scalajs.js.annotation.JSExport
109

1110
object Context {
1211
implicit val executionContext = scalajs.concurrent.JSExecutionContext.Implicits.queue
1312
private val routingRegistry = new RoutingRegistryDef
1413
private val viewPresenterRegistry = new StatesToViewPresenterDef
1514

16-
implicit val applicationInstance = new Application[RoutingState](routingRegistry, viewPresenterRegistry, RootState)
15+
implicit val applicationInstance = new Application[RoutingState](routingRegistry, viewPresenterRegistry)
1716
}
1817

1918
object Init {

example/src/main/scala/io/udash/demos/jquery/states.scala

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,31 @@ package io.udash.demos.jquery
22

33
import io.udash._
44

5-
sealed abstract class RoutingState(val parentState: RoutingState) extends State {
6-
def url(implicit application: Application[RoutingState]): String = s"#${application.matchState(this).value}"
7-
}
8-
9-
case object RootState extends RoutingState(null)
10-
11-
case object ErrorState extends RoutingState(RootState)
12-
13-
case object IndexState extends RoutingState(RootState)
14-
15-
case object AddState extends RoutingState(RootState)
16-
17-
case object AddBackState extends RoutingState(RootState)
18-
19-
case object AfterBeforeState extends RoutingState(RootState)
20-
21-
case object AnimateState extends RoutingState(RootState)
22-
23-
case object AppendPrependState extends RoutingState(RootState)
5+
sealed abstract class RoutingState(val parentState: Option[ContainerRoutingState]) extends State {
6+
type HierarchyRoot = RoutingState
247

25-
case object AttrState extends RoutingState(RootState)
26-
27-
case object CallbacksState extends RoutingState(RootState)
28-
29-
case object ChildrenState extends RoutingState(RootState)
30-
31-
case object DataState extends RoutingState(RootState)
32-
33-
case object DeferredState extends RoutingState(RootState)
34-
35-
case object EachState extends RoutingState(RootState)
36-
37-
case object HideShowState extends RoutingState(RootState)
38-
39-
case object OffsetPositionState extends RoutingState(RootState)
8+
def url(implicit application: Application[RoutingState]): String =
9+
s"#${application.matchState(this).value}"
10+
}
4011

41-
case object OnOneOffState extends RoutingState(RootState)
12+
sealed abstract class ContainerRoutingState(parentState: Option[ContainerRoutingState]) extends RoutingState(parentState) with ContainerState
13+
sealed abstract class FinalRoutingState(parentState: ContainerRoutingState) extends RoutingState(Option(parentState)) with FinalState
14+
15+
16+
case object RootState extends ContainerRoutingState(None)
17+
case object ErrorState extends FinalRoutingState(RootState)
18+
case object IndexState extends FinalRoutingState(RootState)
19+
case object AddState extends FinalRoutingState(RootState)
20+
case object AddBackState extends FinalRoutingState(RootState)
21+
case object AfterBeforeState extends FinalRoutingState(RootState)
22+
case object AnimateState extends FinalRoutingState(RootState)
23+
case object AppendPrependState extends FinalRoutingState(RootState)
24+
case object AttrState extends FinalRoutingState(RootState)
25+
case object CallbacksState extends FinalRoutingState(RootState)
26+
case object ChildrenState extends FinalRoutingState(RootState)
27+
case object DataState extends FinalRoutingState(RootState)
28+
case object DeferredState extends FinalRoutingState(RootState)
29+
case object EachState extends FinalRoutingState(RootState)
30+
case object HideShowState extends FinalRoutingState(RootState)
31+
case object OffsetPositionState extends FinalRoutingState(RootState)
32+
case object OnOneOffState extends FinalRoutingState(RootState)

example/src/main/scala/io/udash/demos/jquery/views/ErrorView.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package io.udash.demos.jquery.views
22

33
import io.udash._
44
import io.udash.demos.jquery.IndexState
5-
import org.scalajs.dom.Element
65

7-
object ErrorViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new ErrorView)
6+
object ErrorViewPresenter extends StaticViewFactory[IndexState.type](() => new ErrorView)
87

98
class ErrorView extends FinalView {
109
import scalatags.JsDom.all._

example/src/main/scala/io/udash/demos/jquery/views/IndexView.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package io.udash.demos.jquery.views
22

33
import io.udash._
44
import io.udash.demos.jquery._
5-
import org.scalajs.dom.Element
65

7-
object IndexViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new IndexView)
6+
object IndexViewPresenter extends StaticViewFactory[IndexState.type](() => new IndexView)
87

98
class IndexView extends FinalView {
109
import Context._
11-
1210
import scalatags.JsDom.all._
1311

1412
private val content = div(

example/src/main/scala/io/udash/demos/jquery/views/RootView.scala

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,15 @@ package io.udash.demos.jquery.views
22

33
import io.udash._
44
import io.udash.demos.jquery.{Context, IndexState, RootState}
5-
import org.scalajs.dom.Element
65

7-
object RootViewPresenter extends DefaultViewPresenterFactory[RootState.type](() => new RootView)
6+
object RootViewPresenter extends StaticViewFactory[RootState.type](() => new RootView)
87

9-
class RootView extends View {
8+
class RootView extends ContainerView {
109
import Context._
11-
1210
import scalatags.JsDom.all._
1311

14-
private var child: Element = div().render
15-
16-
private val content = div(
12+
override def getTemplate: Modifier = div(
1713
a(href := IndexState.url)(h1("jquery-demo")),
18-
child
14+
childViewContainer
1915
)
20-
21-
override def getTemplate: Modifier = content
22-
23-
override def renderChild(view: View): Unit = {
24-
import io.udash.wrappers.jquery._
25-
26-
jQ(child).children().remove()
27-
view.getTemplate.applyTo(child)
28-
}
2916
}

example/src/main/scala/io/udash/demos/jquery/views/functions/AddBackView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import io.udash.wrappers.jquery._
77

88
import scalatags.JsDom.tags2
99

10-
object AddBackViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AddBackView)
10+
object AddBackViewPresenter extends StaticViewFactory[IndexState.type](() => new AddBackView)
1111

1212
/** Based on examples from: <a href="http://api.jquery.com/addBack/">jQuery Docs</a>. */
1313
class AddBackView extends FunctionView {

example/src/main/scala/io/udash/demos/jquery/views/functions/AddView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import io.udash.wrappers.jquery._
77

88
import scalatags.JsDom.tags2
99

10-
object AddViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AddView)
10+
object AddViewPresenter extends StaticViewFactory[IndexState.type](() => new AddView)
1111

1212
/** Based on examples from: <a href="http://api.jquery.com/add/">jQuery Docs</a>. */
1313
class AddView extends FunctionView {

example/src/main/scala/io/udash/demos/jquery/views/functions/AfterView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import io.udash.demos.jquery.IndexState
55
import io.udash.demos.jquery.views.FunctionView
66
import io.udash.wrappers.jquery._
77

8-
object AfterBeforeViewPresenter extends DefaultViewPresenterFactory[IndexState.type](() => new AfterBeforeView)
8+
object AfterBeforeViewPresenter extends StaticViewFactory[IndexState.type](() => new AfterBeforeView)
99

1010
/** Based on examples from: <a href="http://api.jquery.com/after/">jQuery Docs</a>. */
1111
class AfterBeforeView extends FunctionView {

0 commit comments

Comments
 (0)