Skip to content

Commit

Permalink
update to scalajs 1.0.0-M1
Browse files Browse the repository at this point in the history
  • Loading branch information
chandu0101 committed Jul 8, 2017
1 parent 923d8fe commit bc4e41e
Show file tree
Hide file tree
Showing 27 changed files with 2,539 additions and 263 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore" : ["sjs.test.js"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ npm-debug.log


#project
*.test.js
*.test.js.map
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ env:
JSENV=node

script:
- sbt ++$TRAVIS_SCALA_VERSION test:fastOptJS test:fullOptJS
- sbt ++$TRAVIS_SCALA_VERSION 'set parallelExecution in ThisBuild := false' test
- sbt ++$TRAVIS_SCALA_VERSION 'set parallelExecution in ThisBuild := false' 'set scalaJSStage in ThisBuild := FullOptStage' test
- sbt ++$TRAVIS_SCALA_VERSION testDev testProd


deploy:
Expand Down
10 changes: 10 additions & 0 deletions __mocks__/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const react = require('react');
// Resolution for requestAnimationFrame not supported in jest error :
// https://github.com/facebook/react/issues/9102#issuecomment-283873039
global.window = global;
window.addEventListener = () => {};
window.requestAnimationFrame = () => {
throw new Error('requestAnimationFrame is not supported in Node');
};

module.exports = react;
49 changes: 41 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "web-router"

//version := "2017.5.0-SNAPSHOT"
//version := "2017.7.0-SNAPSHOT"

enablePlugins(ScalaJSPlugin)

Expand All @@ -22,8 +22,8 @@ scalacOptions ++= Seq(
//deps

libraryDependencies ++= Seq(
"scalajs-react-interface" %%% "core" % "2017.4.23-beta" % Provided,
"scalajs-react-interface" %%% "universal" % "2017.5.2-beta" % Provided)
"scalajs-react-interface" %%% "core" % "2017.7.9-RC" % Provided,
"scalajs-react-interface" %%% "universal" % "2017.7.9-RC" % Provided)

//bintray
resolvers += Resolver.jcenterRepo
Expand All @@ -40,10 +40,43 @@ bintrayRepository := "maven"
publishArtifact in Test := false

//Test
scalaJSModuleKind in Test := ModuleKind.CommonJSModule

resolvers += Resolver.bintrayRepo("scalajs-react-interface", "maven")
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.0.0" % Test,
"scalajs-react-interface" %%% "web" % "2017.3.26-beta" % Test)
scalaJSUseMainModuleInitializer in Test := true

scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))

val TEST_FILE = s"./sjs.test.js"

artifactPath in Test in fastOptJS := new File(TEST_FILE)
artifactPath in Test in fullOptJS := new File(TEST_FILE)

val testDev = Def.taskKey[Unit]("test in dev mode")
val testProd = Def.taskKey[Unit]("test in prod mode")

testDev := {
(fastOptJS in Test).value
runJest()
}

scalaJSStage in Global := FastOptStage
testProd := {
(fullOptJS in Test).value
runJest()
}

def runJest() = {
import sys.process._
val jestResult = "npm test".!
if (jestResult != 0) throw new IllegalStateException("Jest Suite failed")
}

resolvers += Resolver.bintrayRepo("scalajs-react-interface", "maven")
resolvers += Resolver.bintrayRepo("scalajs-jest", "maven")

libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.9.3" % Test,
"scalajs-jest" %%% "core" % "2017.7.9-beta" % Test,
"scalajs-react-interface" %%% "web" % "2017.7.9-RC" % Test
)
//scalaJSStage in Global := FastOptStage
scalaJSStage in Global := FullOptStage
16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
"url": ""
},
"scripts": {
"start": "webpack --watch & webpack-dev-server --progress --colors --port 8090",
"build": "webpack --watch"
},
"devDependencies": {
"jsdom-global": "2.1.1",
"webpack": "^1.9.10"
"test": "jest"
},
"devDependencies": {},
"dependencies": {
"history": "^4.6.1",
"jsdom": "10.1.0",
"react": "15.5.4",
"react-addons-test-utils": "15.5.1",
"react-dom": "15.5.4"
"jest": "^20.0.4",
"path-to-regexp": "^1.7.0",
"react": "next",
"react-dom": "next"
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sbt.version=0.13.13
sbt.version=0.13.15

4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "1.1.1")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "1.3.0")
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
10 changes: 3 additions & 7 deletions src/main/scala/sri/web/router/History.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import sri.macros.{FunctionObjectMacro, OptDefault, OptionalParam}

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSImport, JSName, ScalaJSDefined}
import scala.scalajs.js.|

@js.native
trait History extends js.Object {

def listen(listener: js.Function2[Location, String, _]): js.Function0[_] =
js.native

def block(listener: js.Function2[Location, String, _]): js.Function0[_] =
def block(
message: String | js.Function2[Location, String, _]): js.Function0[_] =
js.native

def block(message: String): js.Function0[_] = js.native

def push(location: Location): Unit = js.native

def replace(location: Location): Unit = js.native
Expand Down Expand Up @@ -59,7 +59,6 @@ object History extends js.Object {

}

@ScalaJSDefined
class Location(val pathname: String,
val basename: js.UndefOr[String] = js.undefined,
val hash: js.UndefOr[String] = js.undefined,
Expand All @@ -69,13 +68,10 @@ class Location(val pathname: String,
val key: String = "")
extends js.Object {}

@ScalaJSDefined
trait HistoryOptions extends js.Object

@ScalaJSDefined
trait BrowserHistoryOptions extends HistoryOptions

@ScalaJSDefined
trait HashHistoryOptions extends HistoryOptions

object BrowserHistoryOptions {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/sri/web/router/NavigationAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ object NavigationAction {

@inline def REPLACE = "REPLACE".asInstanceOf[NavigationAction]

@inline def POP = "POP".asInstanceOf[NavigationAction]

}
1 change: 0 additions & 1 deletion src/main/scala/sri/web/router/PathToRegexP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sri.web.router

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

@js.native
trait PathRegexp extends js.Object {
Expand Down
66 changes: 66 additions & 0 deletions src/main/scala/sri/web/router/RouteChangePrompt.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package sri.web.router

import sri.core.{CreateElement, JSProps}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportStatic
import scala.scalajs.js.|

/**
* Thank you react-router and history dev :)
*/
class RouteChangePrompt
extends RouterAwareComponentP[RouteChangePrompt.Props] {

override def componentWillMount(): Unit = {
if (props.blockTransition) enable(props.message)
}

def render() = {
null
}

var unblock: js.Function0[_] = null

def enable(message: String | js.Function2[Location, String, _]) = {
if (unblock != null) {
unblock()
}
unblock = navigation.config.history.block(props.message)
}

override def componentWillReceiveProps(nextJSProps: JSProps {
type ScalaProps = RouteChangePrompt.Props
}): Unit = {
if (nextJSProps.scalaProps.blockTransition) {
if (!props.blockTransition || (props.message != nextJSProps.scalaProps.message)) {
enable(nextJSProps.scalaProps.message)
}

} else disable()
}

def disable() = {
if (unblock != null) {
unblock()
unblock = null
}
}

override def componentWillUnmount(): Unit = {
disable()
}
}

object RouteChangePrompt {

@JSExportStatic
val contextTypes = navigationContext

case class Props(blockTransition: Boolean,
message: String | js.Function2[Location, String, _])

def apply(blockTransition: Boolean,
message: String | js.Function2[Location, String, _]) =
CreateElement[RouteChangePrompt](Props(blockTransition, message))
}
22 changes: 0 additions & 22 deletions src/main/scala/sri/web/router/RouteDefinitions.scala

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/scala/sri/web/router/RouteNotFound.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sri.web.router

case class RouteNotFound(page: String,
case class RouteNotFound(page: RouterScreenKey,
action: NavigationAction = NavigationAction.REPLACE)
22 changes: 9 additions & 13 deletions src/main/scala/sri/web/router/RouteUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package sri.web.router
import sri.universal._

import scala.scalajs.js
import scala.scalajs.js.annotation.ScalaJSDefined

object RouteUtils {

def setCurrentRoute(loc: Location, ctrl: RouterCtrl) = {
def getRouteFromLocation(loc: Location, ctrl: RouterCtrl): Route = {
var result: Route = null
var placeholder = ""
var params: js.UndefOr[js.Object] = js.undefined
var paramsLocal: js.UndefOr[js.Object] = js.undefined
// first check in static routes
val pathname =
if (loc.pathname == "/") "/" else loc.pathname.removeTrailingSlash
Expand All @@ -37,19 +35,17 @@ object RouteUtils {
(key.name, values(index + 1))
}
}
params = js.Dictionary(pairs: _*).asInstanceOf[js.Object]
paramsLocal = js.Dictionary(pairs: _*).asInstanceOf[js.Object]
} else {
result = ctrl.config.staticRoutes
.getOrElse(ctrl.config.notFound.page, ctrl.config.initialRoute._2)
.getOrElse(ctrl.config.notFound.page.toString,
ctrl.config.staticRoutes.head._2)
}
}
if (ctrl._currentRoute.action.isDefined)
ctrl._previousRoute = ctrl.currentRoute
result = result.copy(action = loc.action,
search = loc.search,
state = loc.state,
params = params)
ctrl._currentRoute = result
result.copy(action = loc.action,
search = loc.search,
state = loc.state,
params = paramsLocal)
}

}
Loading

0 comments on commit bc4e41e

Please sign in to comment.