File tree Expand file tree Collapse file tree 9 files changed +153
-3
lines changed
js/src/main/scala/downstream
tests/src/test/scala/japgolly/scalajs/react/test Expand file tree Collapse file tree 9 files changed +153
-3
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,26 @@ lazy val jsCE = project
173173 },
174174 )
175175
176+ lazy val jsCBIO = project
177+ .in(file(" js-cbio" ))
178+ .enablePlugins(ScalaJSPlugin )
179+ .dependsOn(macros)
180+ .configure(commonSettings, utestSettings, addReactJsDependencies(Test ))
181+ .settings(
182+ scalaJSStage := jsStage,
183+ libraryDependencies ++= {
184+ val ver = version.value.stripSuffix(" -SNAPSHOT" ) + " -SNAPSHOT"
185+ Seq (
186+ " com.github.japgolly.scalajs-react" %%% " core-bundle-cb_io" % ver,
187+ " com.github.japgolly.scalajs-react" %%% " extra" % ver,
188+ " com.github.japgolly.scalajs-react" %%% " test" % ver % Test ,
189+ Dep .microlibsCompileTime.value % Test ,
190+ Dep .microlibsTestUtil.value % Test ,
191+ Dep .scalaJsJavaTime.value % Test ,
192+ )
193+ },
194+ )
195+
176196lazy val generic = project
177197 .enablePlugins(ScalaJSPlugin )
178198 .configure(commonSettings)
Original file line number Diff line number Diff line change 1+ package downstream
2+
3+ import cats .effect .IO
4+ import japgolly .scalajs .react ._
5+ import japgolly .scalajs .react .vdom .html_<^ ._
6+
7+ object Catnip {
8+
9+ final class Backend ($ : BackendScope [String , Int ]) {
10+ def render (p : String , s : Int ) =
11+ < .div(s " Hello( $s) " , p)
12+
13+ def onMount : Callback =
14+ $.props.map { p =>
15+ Globals .catnipMounts :+= p
16+ }
17+
18+ def onMount2 : IO [Unit ] =
19+ $.setStateAsync(1 )
20+ }
21+
22+ val Component = ScalaComponent .builder[String ]
23+ .initialState(0 )
24+ .renderBackend[Backend ]
25+ .componentDidMount($ => $.backend.onMount2)
26+ .build
27+ }
Original file line number Diff line number Diff line change 1+ package downstream
2+
3+ import japgolly .scalajs .react ._
4+ import japgolly .scalajs .react .extra ._
5+ import scala .scalajs .js .annotation ._
6+
7+ @ JSExportTopLevel (" EXPORTS" )
8+ object Exports {
9+
10+ @ JSExport
11+ def exp = List [Any ](
12+ Routed .Component ,
13+ pxToCallback,
14+ )
15+
16+ private def pxToCallback : CallbackTo [Int ] = {
17+ val x = Px .constByNeed(123 ).toCallback
18+ x
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package downstream
2+
3+ object Globals {
4+
5+ var catnipMounts = List .empty[String ]
6+
7+ def clear (): Unit = {
8+ catnipMounts = Nil
9+ }
10+
11+ clear()
12+ }
Original file line number Diff line number Diff line change 1+ package downstream
2+
3+ import japgolly .scalajs .react ._
4+ import japgolly .scalajs .react .extra .router ._
5+ import japgolly .scalajs .react .vdom .html_<^ ._
6+
7+ object Routed {
8+
9+ sealed trait Module
10+ case object ModuleRoot extends Module
11+ case object Module1 extends Module
12+ case class Module2 (i : Int ) extends Module
13+
14+ val routerConfig = RouterConfigDsl [Module ].buildConfig { dsl =>
15+ import dsl ._
16+
17+ def moduleRoot (ctl : RouterCtl [Module ]) =
18+ < .div(
19+ ctl.link(Module1 )(" Module One" ),
20+ ctl.link(Module2 (7 ))(" Module 2.7" ),
21+ )
22+
23+ (emptyRule
24+ | staticRoute(root, ModuleRoot ) ~> renderR(moduleRoot)
25+ | staticRoute(" one" , Module1 ) ~> render(< .h3(" Module #1" ))
26+ | dynamicRouteCT(" two" / int.caseClass[Module2 ]) ~> dynRender(m => < .h3(s " Module #2 @ ${m.i}" ))
27+ )
28+ .notFoundDynamic(_ => CallbackTo (redirectToPage(ModuleRoot )(SetRouteVia .HistoryReplace )))
29+ .verify(ModuleRoot , Module1 , Module2 (2 ))
30+ }
31+
32+ val Component = RouterWithProps (BaseUrl (" http://localhost/" ), routerConfig)
33+
34+ }
Original file line number Diff line number Diff line change 1+ package downstream
2+
3+ import japgolly .microlibs .testutil .TestUtil ._
4+ import japgolly .scalajs .react .test .ReactTestUtils ._
5+ import utest ._
6+ import scala .concurrent .Future
7+ import scala .concurrent .Promise
8+ import concurrent .ExecutionContext .Implicits .global
9+ import cats .effect .IO
10+ import scalajs .js
11+
12+ object CBIOBundleTests extends TestSuite {
13+
14+ def delay (milliseconds : Int ): Future [Unit ] = {
15+ val p = Promise [Unit ]()
16+ js.timers.setTimeout(milliseconds) {
17+ p.success(())
18+ }
19+ p.future
20+ }
21+
22+ override def tests = Tests {
23+ Globals .clear()
24+
25+ " catnip" - {
26+ // withRenderedIntoDocumentAsync(Catnip.Component("omg")) { m =>
27+ withRenderedIntoDocumentFuture(Catnip .Component (" omg" )) { m =>
28+ delay(500 ).map(_ =>
29+ // assertEq(Globals.catnipMounts, List("omg"))
30+ assertEq(m.showDom(), " <div>Hello(1) omg</div>" )
31+ )
32+ }
33+ // assertEq(Globals.catnipMounts, List("omg"))
34+ }
35+
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ object Exports {
2626 )
2727
2828 private def modStateFnPure : ModStateFnPure [Int ] =
29- ModStateFn ((mod, cb) => Callback .log(mod(1 ).isDefined) >> cb )
29+ ModStateFn ((mod, cb) => Callback .log(mod(1 ).isDefined) >> Callback (cb()) )
3030
3131 private def pxToCallback : CallbackTo [Int ] = {
3232 val x = Px .constByNeed(123 ).toCallback
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ all_tests_values=(
1818 " -Ddownstream_tests.fullOptJS -Ddownstream_tests.reusability.dev=overlay"
1919)
2020all_tests_keys=()
21- declare -A all_tests
21+ declare -a all_tests
2222i=0
2323for t in " ${all_tests_values[@]} " ; do
2424 i=$(( i+ 1 ))
Original file line number Diff line number Diff line change @@ -253,7 +253,7 @@ object TestTest extends TestSuite {
253253 assert(body1 == body2)
254254 }
255255
256- " withRenderedIntoDocumentAsync " - {
256+ " withRenderedIntoDocumentFuture " - {
257257 var m : ScalaComponent .MountedImpure [Unit , Boolean , Unit ] = null
258258 val promise : Promise [Unit ] = Promise [Unit ]()
259259 ReactTestUtils .withRenderedIntoDocumentFuture(IC ()) { mm =>
You can’t perform that action at this time.
0 commit comments