Skip to content

Commit 2d1393a

Browse files
authored
Merge pull request #1002 from japgolly/topic/cbio2
Add CB/IO core bundle
2 parents 5e473f1 + 31eace0 commit 2d1393a

File tree

16 files changed

+205
-5
lines changed

16 files changed

+205
-5
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ val callbackExtCats = ScalaJsReact.callbackExtCats
1010
val callbackExtCatsEffect = ScalaJsReact.callbackExtCatsEffect
1111
val coreBundleCallback = ScalaJsReact.coreBundleCallback
1212
val coreBundleCatsEffect = ScalaJsReact.coreBundleCatsEffect
13+
val coreBundleCBIO = ScalaJsReact.coreBundleCBIO
1314
val coreExtCats = ScalaJsReact.coreExtCats
1415
val coreExtCatsEffect = ScalaJsReact.coreExtCatsEffect
1516
val coreGeneric = ScalaJsReact.coreGeneric
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../coreBundleCallback/src/main/scala/japgolly/scalajs/react/internal/ReactCallbackExtensions.scala
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package japgolly.scalajs
2+
3+
import japgolly.scalajs.react.util.DefaultEffects._
4+
5+
package object react
6+
extends japgolly.scalajs.react.internal.CoreGeneralF[Sync]
7+
with japgolly.scalajs.react.internal.ReactCallbackExtensions
8+
with japgolly.scalajs.react.callback.Exports
9+
with japgolly.scalajs.react.ReactCats
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package japgolly.scalajs.react.util
2+
3+
import cats.effect._
4+
import japgolly.scalajs.react.callback._
5+
6+
// DefaultEffects
7+
8+
sealed trait DefaultEffectsLowPri extends DefaultEffectsApiLowPri {
9+
override final type Async[A] = IO[A]
10+
@inline override final implicit lazy val Async: EffectCatsEffect.io.type = EffectCatsEffect.io
11+
}
12+
13+
object DefaultEffects extends DefaultEffectsLowPri with DefaultEffectsApi {
14+
override type Sync[A] = CallbackTo[A]
15+
@inline override implicit val Sync: EffectCallback.callback.type = EffectCallback.callback
16+
}
17+
18+
// Effect highest-priority
19+
20+
abstract class EffectFallbacks extends EffectFallbacks1 {
21+
override implicit def callback: Effect.Sync [CallbackTo] = EffectCallback.callback
22+
override implicit def io : Effect.Async[IO ] = EffectCatsEffect.io
23+
}

coreExtCatsEffect/src/main/scala/japgolly/scalajs/react/util/EffectCatsEffect.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ object EffectCatsEffect {
3939

4040
// ===================================================================================================================
4141

42-
implicit object io extends AsyncIO(ReactCatsEffect.runtimeFn)
42+
implicit lazy val io: AsyncIO =
43+
new AsyncIO(ReactCatsEffect.runtimeFn)
4344

4445
class AsyncIO(runtime: () => IORuntime) extends Async.WithDefaults[IO] {
4546

coreGeneric/src/main/scala/japgolly/scalajs/react/component/ScalaFn.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package japgolly.scalajs.react.component
33
import japgolly.scalajs.react.hooks.HookComponentBuilder
44
import japgolly.scalajs.react.internal._
55
import japgolly.scalajs.react.vdom.VdomNode
6-
import japgolly.scalajs.react.{Children, CtorType, PropsChildren, facade}
6+
import japgolly.scalajs.react.{Children, CtorType, PropsChildren, Reusability, facade}
77
import scala.scalajs.js
8-
import japgolly.scalajs.react.Reusability
98

109
object ScalaFn {
1110

doc/MODULES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ with the opt-in optional features shown for you to accept or remove.
1515
Add to sbt:
1616

1717
```scala
18-
val ScalaJsReactVer = "2.0.0-RC3"
18+
val ScalaJsReactVer = "<latest>"
1919

2020
libraryDependencies ++= Seq(
2121

@@ -118,6 +118,7 @@ These are all the modules meant for end-user selection.
118118
| `callback-ext-cats_effect` | For classes in the `callback` module: <ul><li>`cats.effect.{Sync,Async}` instances</li><li>Conversions from/to `cats.effect.{SyncIO,IO}`</li></ul> |
119119
| `core` | Core scalajs-react functionality with `{Callback,AsyncCallback}` as the default effects |
120120
| `core-bundle-cats_effect` | Core scalajs-react functionality with `cats.effect.{SyncIO,IO}` as the default effects<br>*(Note: `callback` module not included. Add as a separate dependency if required.)* |
121+
| `core-bundle-cb_io` | Core scalajs-react functionality with `Callback` as the default sync effect and `cats.effect.IO` as the default async effect.<br>*(Note: both `callback` and `core-ext-cats_effect` modules are included.)* |
121122
| `core-ext-cats` | Extensions to the `core` module for Cats |
122123
| `core-ext-cats_effect` | Extensions to the `core` module for Cats Effect |
123124
| `extra` | Optional utils exclusive to scalajs-react. ([details](./EXTRA.md)) |

doc/changelog/2.0.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ You can run the script in the Migration section at the bottom of the page to aut
374374
* UnivEq to 2.0.0
375375
376376
377+
# Changes in RC5
378+
* Add a new bundle called `core-bundle-cb_io` with provides core scalajs-react functionality with `Callback` as the default sync effect and `cats.effect.IO` as the default async effect. (Thanks [@rpiaggio](https://github.com/rpiaggio))
379+
380+
s
377381
# Thanks
378382
379383
A lot of this was kindly sponsored by [Gemini](https://www.gemini.edu/)/[NOIRLab](https://nationalastro.org/)/[AURA](https://www.aura-astronomy.org/).

downstream-tests/build.sbt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ lazy val root = Project("root", file("."))
8080
jvm / clean,
8181
js / clean,
8282
jsCE / clean,
83+
jsCBIO / clean,
8384
Test / compile,
8485
jvm / Test / test,
8586
js / Test / test,
8687
jsCE / Test / test,
88+
jsCBIO / Test / test
8789
).value
8890
else
8991
Def.sequential(
@@ -174,6 +176,26 @@ lazy val jsCE = project
174176
},
175177
)
176178

179+
lazy val jsCBIO = project
180+
.in(file("js-cbio"))
181+
.enablePlugins(ScalaJSPlugin)
182+
.dependsOn(macros)
183+
.configure(commonSettings, utestSettings, addReactJsDependencies(Test))
184+
.settings(
185+
scalaJSStage := jsStage,
186+
libraryDependencies ++= {
187+
val ver = version.value.stripSuffix("-SNAPSHOT") + "-SNAPSHOT"
188+
Seq(
189+
"com.github.japgolly.scalajs-react" %%% "core-bundle-cb_io" % ver,
190+
"com.github.japgolly.scalajs-react" %%% "extra" % ver,
191+
"com.github.japgolly.scalajs-react" %%% "test" % ver % Test,
192+
Dep.microlibsCompileTime.value % Test,
193+
Dep.microlibsTestUtil.value % Test,
194+
Dep.scalaJsJavaTime.value % Test,
195+
)
196+
},
197+
)
198+
177199
lazy val generic = project
178200
.enablePlugins(ScalaJSPlugin)
179201
.configure(commonSettings)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.onMount)
26+
.componentDidMount(_.backend.onMount2)
27+
.build
28+
}

0 commit comments

Comments
 (0)