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 984eb0f commit 5d4f561
Show file tree
Hide file tree
Showing 18 changed files with 2,215 additions and 130 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
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,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:
provider: script
Expand Down
46 changes: 41 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "navigation"

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

enablePlugins(ScalaJSPlugin)

Expand All @@ -21,8 +21,9 @@ scalacOptions ++= Seq(

//Dependencies

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

//bintray
resolvers += Resolver.jcenterRepo
Expand All @@ -40,5 +41,40 @@ publishArtifact in Test := false

//Test
resolvers += Resolver.bintrayRepo("scalajs-react-interface", "maven")
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.0" % Test
scalaJSStage in Global := FastOptStage
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()
}

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
)
//scalaJSStage in Global := FastOptStage
scalaJSStage in Global := FullOptStage
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
"url": ""
},
"scripts": {
"start": "webpack --watch & webpack-dev-server --progress --colors --port 8090",
"build": "webpack --watch"
},
"devDependencies": {
"jsdom-global": "2.1.1",
"jsdom": "^9.9.1"
"test": "jest"
},
"devDependencies": {},
"dependencies": {

"jest": "^20.0.4"
}
}
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.15")
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")
14 changes: 12 additions & 2 deletions src/main/scala/sri/navigation/CreateNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ import scala.scalajs.js.annotation.JSImport

@JSImport("react-navigation", "createNavigator")
@js.native
object CreateNavigator extends js.Object {
object CreateNavigatorJS extends js.Object {
type NavigatorView =
js.Function1[NavigatorScreenProps[_], ReactElement]
def apply(router: NavigationRouter)
: js.Function1[NavigatorView, NavigationNavigatorConstructor] = js.native
: js.Function1[NavigationNavigatorComponentConstructor,
NavigationNavigatorConstructor] =
js.native
}

object CreateNavigator {

@inline
def apply[C <: NavigatorViewComponentClass: js.ConstructorTag](
router: NavigationRouter): NavigationNavigatorConstructor =
CreateNavigatorJS(router)(navigationNavigatorComponentConstructor[C])
}
145 changes: 111 additions & 34 deletions src/main/scala/sri/navigation/NavigationAwareComponents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,39 @@ package sri.navigation
import sri.core.{
=:!=,
Component,
ComponentConstructor,
ComponentJS,
ComponentNoPS,
ComponentP,
ComponentS,
CreateElement,
InternalComponentP,
React,
ReactClass,
ReactJSProps
ReactScalaClass
}

import scala.language.existentials
import scala.reflect.ClassTag
import scala.scalajs.js
import scala.scalajs.js.ConstructorTag
import scala.scalajs.js.annotation.ScalaJSDefined
import scala.scalajs.js.annotation.JSExportStatic

@ScalaJSDefined
trait ScreenClass extends ReactClass {
type ParamsType <: js.Object
}

@ScalaJSDefined
abstract class NavigationScreenComponentP[P >: Null <: js.Object](
implicit ev: =:!=[P, Null])
extends NavigationScreenComponent[P, Null] {}

@ScalaJSDefined
abstract class NavigationScreenComponentNoPS
extends NavigationScreenComponent[Null, Null]

@ScalaJSDefined
abstract class NavigationScreenComponentS[S <: AnyRef](
implicit ev: =:!=[S, Null])
extends NavigationScreenComponent[Null, S]

@ScalaJSDefined
abstract class NavigationScreenComponent[Params >: Nothing <: js.Object,
S <: AnyRef](implicit ev: =:!=[Params, Nothing])
extends ComponentJS[NavigatorScreenProps[Params], S]
Expand Down Expand Up @@ -85,57 +84,135 @@ object NavigationCtrl {
navigation.navigate(DRAWER_CLOSE)

}
@ScalaJSDefined
abstract class NavigationAwareComponent[P >: Null <: AnyRef,
S >: Null <: AnyRef](
implicit ev: =:!=[P, Null],
ev2: =:!=[S, Null])
extends Component[P, S] {

@inline
implicit def navigationJS = context.navigation.asInstanceOf[Navigation[_]]
sealed trait NavigationAwareComponentClass extends ReactScalaClass {
override type ScalaPropsType <: AnyRef
}

abstract class NavigationAwareComponent[
P >: Null <: AnyRef, S >: Null <: AnyRef]
extends Component[P, S]
with NavigationAwareComponentClass {

@inline
implicit def navigationJS: Navigation[_] =
jsProps.asInstanceOf[js.Dynamic].navigation.asInstanceOf[Navigation[_]]

def navigation = NavigationCtrl

}

@ScalaJSDefined
abstract class NavigationAwareComponentP[P >: Null <: AnyRef](
implicit ev: =:!=[P, Null])
extends ComponentP[P] {
abstract class NavigationAwareComponentP[P >: Null <: AnyRef]
extends ComponentP[P]
with NavigationAwareComponentClass {

@inline
implicit def navigationJS = context.navigation.asInstanceOf[Navigation[_]]
implicit def navigationJS: Navigation[_] =
jsProps.asInstanceOf[js.Dynamic].navigation.asInstanceOf[Navigation[_]]

def navigation = NavigationCtrl
}

abstract class NavigationAwareComponentS[S >: Null <: AnyRef]
extends ComponentS[S]
with NavigationAwareComponentClass {

@inline
def navigationJS: Navigation[_] =
jsProps.asInstanceOf[js.Dynamic].navigation.asInstanceOf[Navigation[_]]

def navigation = NavigationCtrl
}

@ScalaJSDefined
abstract class NavigationAwareComponentS[S >: Null <: AnyRef](
implicit ev: =:!=[S, Null])
extends ComponentS[S] {
abstract class NavigationAwareComponentNoPS
extends ComponentNoPS
with NavigationAwareComponentClass {

@inline
implicit def navigationJS = context.navigation.asInstanceOf[Navigation[_]]
def navigationJS: Navigation[_] =
jsProps.asInstanceOf[js.Dynamic].navigation.asInstanceOf[Navigation[_]]

def navigation = NavigationCtrl
}

abstract class RouterAwareComponentJS[
P >: Null <: js.Object, S >: Null <: AnyRef]
extends ComponentJS[P, S] {

@inline
implicit def navigationJS: Navigation[_] =
props.asInstanceOf[js.Dynamic].navigation.asInstanceOf[Navigation[_]]
def navigation = NavigationCtrl
}

@ScalaJSDefined
abstract class NavigationAwareComponentNoPS extends ComponentNoPS {
class WithNavigation extends ComponentP[WithNavigation.Props] {

def render() = {
React.createElement(props.ctor,
js.Dynamic.literal(scalaProps =
props.cProps.asInstanceOf[js.Any],
navigation = context.navigation))
}
}

object WithNavigation {

@JSExportStatic
val contextTypes = navigationContextType

case class Props(ctor: js.Any, cProps: Any)

@inline
def apply[C <: NavigationAwareComponentClass {
type ScalaPropsType >: Null <: AnyRef
}: js.ConstructorTag](props: C#ScalaPropsType) = {
val ctor = js.constructorTag[C].constructor
CreateElement[WithNavigation](Props(ctor, props))
}

@inline
def apply[C <: NavigationAwareComponentClass { type ScalaPropsType = Null }: js.ConstructorTag]() = {
val ctor = js.constructorTag[C].constructor
CreateElement[WithNavigation](Props(ctor, null))
}
}

trait NavigatorViewComponentProps extends js.Object {
val router: NavigationRouter
val navigation: Navigation[js.Object]
}

trait NavigatorViewComponentClass extends ReactClass

trait NavigationNavigatorComponentConstructor extends ComponentConstructor

abstract class NavigatorViewComponent[P >: Null <: NavigatorViewComponentProps,
S >: Null <: AnyRef](
implicit ev: =:!=[P, Null],
ev2: =:!=[S, Null])
extends ComponentJS[P, S]
with NavigatorViewComponentClass {

@inline
def router: NavigationRouter = props.router

@inline
implicit def navigationJS = context.navigation.asInstanceOf[Navigation[_]]
implicit def navigationJS = props.navigation.asInstanceOf[Navigation[_]]

@inline
def navigation = NavigationCtrl
}

//object NavigationAwareComponent {
// @JSExportStatic
// val contextTypes =
// js.Dictionary("navigation" -> React.PropTypes.`object`.isRequired)
//
//}
abstract class NavigatorViewComponentP[
P >: Null <: NavigatorViewComponentProps](implicit ev: =:!=[P, Null])
extends ComponentJS[P, Null]
with NavigatorViewComponentClass {
@inline
def router: NavigationRouter = props.router

@inline
implicit def navigationJS = props.navigation.asInstanceOf[Navigation[_]]

@inline
def navigation = NavigationCtrl
}
Loading

0 comments on commit 5d4f561

Please sign in to comment.