-
-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements exclusive to Scala 3.0 #785
Comments
Excerpt from final case class Props(state : State,
setNextState: Callback,
disabled : Boolean = false)
private def render($: ScalaComponent.MountedPure[Props, Unit, Unit], p: Props) = {
val setNext = $.props.flatMap(p => p.setNextState.unless_(p.disabled)) // Only access .setNextState inside the Callback for Reusability
...
}
implicit val reusabilityProps: Reusability[Props] =
Reusability.caseClassExcept("setNextState") // .setNextState is never accessed outside of a Callback Scala 3 could allow something like this (and with erased classes, without incurring any runtime cost!): final case class Props(state : State,
setNextState: Xxxxxxxxxxx[Callback],
disabled : Boolean = false)
private def render($: ScalaComponent.MountedPure[Props, Unit, Unit], p: Props) = {
val setNext = $.props.flatMap(p => p.setNextState.unless_(p.disabled))
...
}
implicit val reusabilityProps: Reusability[Props] =
Reusability.caseClass where
|
Oh man, this is why it'd be good to enforce at the type-level. I just made a mistake above. Accessing the Callback in the render function would void Correction: given [A] Conversion[Xxxxxxxxxxx[A], A](using InRenderFn | InCallback)
// It should actually be this to preserve Reusability
given [A] Conversion[Xxxxxxxxxxx[A], A](using InCallback) No wait a minute.... That's easily hacked: def render(p: Props) = {
val hack = Callback(p.setNextState) // wrong because `p` is fixed
} How on earth can I have this work? def render(p: Props) = {
val good = $.props.flatMap(_.setNextState)
val bad = Callback(p.setNextState)
} I could just solve it really simplistically for the single BackendScope case but that feels a bit limited. def render(p: Props) = {
val good = $.fromProps(_.setNextState) // provide evidence directly from BackendScope
val bad = Callback(p.setNextState) // reject because evidence unavailable
}
trait BackendScope[P, S] {
// obviously rename all of this
def fromProps[A](f: XxxxxxEvidence ?=> P => Xxxxxxxxxxx[A]): A
} ? |
Actually if I were to do something so simple, I wouldn't even need Scala 3 features. We could have this in Scala 2 today. final case class Xxxx[A](unsafeGet: A)
trait BackendScope[P, S] {
def fromProps[A](f: P => Xxxxxxxxxxx[A]): CallbackTo[A] =
props.flatMap(f(_).unsafeGet)
} |
|
erased
to remove compile-time-only constructs from JS outputDone
derives
for typeclassesderives Reusability
The text was updated successfully, but these errors were encountered: