-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: SBT syncs Dependencies have been updated to versions supporting Scala 3, IntelliJ manages to sync the project, this is a nice first step. Introduces a new source folders `scala-2` & `scala-3`, for now the assumption is that `scala-2.13+` will be included for Scala 3. Set Scala 3 as default version. * WIP: Read/Write Macros split Read/Write is now split between Scala 2&3, Scala 2 compiles as before, Scala 3 is still missing an implementation. * ScalaJSReactInterop cross compile Scala 2&3 * WIP: Core macros split Macros in Core is now split between Scala 2&3, Scala 2 compiles as before, Scala 3 is still missing an implementation. * wip: make more modules compile on Scala 3 * comment out tests that don't compile yet on Scala 3 * basic product derivation for reader/writer using mirrors * readwrite: add basic sum type derivation; disable union types * readwrite: support scala 3 union through macros * initial impl of macros for providers and functional component name * tests: uncomment already working ones * readwrite: fix c&p mistakes in external props provider; use by-name implicits to fix self-ref * readwrite: first pass on value type support * readwrite: support recursive case classes and existing in-scope instances * readwrite: hacky support for default values * readwrite: move all extra type-info macros into one place * readwrite: add fallback reader/writer to general macro * fix cross-compilation with scala 2 * wip: restore scala-2-only tests; use scala 2.13 as default in build * Drop scalajs 0.6 from CI matrix; bump 1.x to 1.6.0 * fix by-name implicits used in scala 2; format code * format build files * don't build native and vr with scala 3 * fix build format once again * bump scalajs-dom to 2.0.0 * review comments * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Arman Bilge <[email protected]> Co-authored-by: Alexander Samsig <[email protected]> Co-authored-by: Arman Bilge <[email protected]>
- Loading branch information
1 parent
b1dd3f4
commit e8571ec
Showing
61 changed files
with
1,303 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ idea/ | |
.vscode/ | ||
project/.bloop/ | ||
publishing-setup/ | ||
|
||
.bsp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
core/src/main/scala-2/slinky/core/ExternalPropsWriterProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package slinky.core | ||
|
||
import scala.scalajs.js | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.whitebox | ||
|
||
// same as PropsWriterProvider except it always returns the typeclass instead of nulling it out in fullOpt mode | ||
trait ExternalPropsWriterProvider extends js.Object | ||
object ExternalPropsWriterProvider { | ||
def impl(c: whitebox.Context): c.Expr[ExternalPropsWriterProvider] = { | ||
import c.universe._ | ||
val compName = c.internal.enclosingOwner.owner.asClass | ||
val q"$_; val x: $typedReaderType = null" = c.typecheck( | ||
q"@_root_.scala.annotation.unchecked.uncheckedStable val comp: $compName = null; val x: _root_.slinky.readwrite.Writer[comp.Props] = null" | ||
) // scalafix:ok | ||
val tpcls = c.inferImplicitValue(typedReaderType.tpe.asInstanceOf[c.Type]) | ||
c.Expr(q"$tpcls.asInstanceOf[_root_.slinky.core.ExternalPropsWriterProvider]") | ||
} | ||
|
||
implicit def get: ExternalPropsWriterProvider = macro impl | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/scala-2/slinky/core/FunctionalComponentName.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package slinky.core | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.whitebox | ||
|
||
final class FunctionalComponentName(val name: String) extends AnyVal | ||
object FunctionalComponentName { | ||
implicit def get: FunctionalComponentName = macro FunctionalComponentNameMacros.impl | ||
} | ||
|
||
object FunctionalComponentNameMacros { | ||
def impl(c: whitebox.Context): c.Expr[FunctionalComponentName] = { | ||
import c.universe._ | ||
|
||
// from lihaoyi/sourcecode | ||
def isSyntheticName(name: String) = | ||
name == "<init>" || (name.startsWith("<local ") && name.endsWith(">")) || name == "component" | ||
|
||
@scala.annotation.tailrec | ||
def findNonSyntheticOwner(current: Symbol): Symbol = | ||
if (isSyntheticName(current.name.decodedName.toString.trim)) { | ||
findNonSyntheticOwner(current.owner) | ||
} else { | ||
current | ||
} | ||
|
||
c.Expr( | ||
q"new _root_.slinky.core.FunctionalComponentName(${findNonSyntheticOwner(c.internal.enclosingOwner).name.decodedName.toString})" | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/scala-2/slinky/core/StateReaderProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package slinky.core | ||
|
||
import scala.scalajs.js | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.whitebox | ||
|
||
trait StateReaderProvider extends js.Object | ||
object StateReaderProvider { | ||
def impl(c: whitebox.Context): c.Expr[StateReaderProvider] = { | ||
import c.universe._ | ||
val compName = c.internal.enclosingOwner.owner.asClass | ||
val q"$_; val x: $typedReaderType = null" = c.typecheck( | ||
q"@_root_.scala.annotation.unchecked.uncheckedStable val comp: $compName = null; val x: _root_.slinky.readwrite.Reader[comp.State] = null" | ||
) // scalafix:ok | ||
val tpcls = c.inferImplicitValue(typedReaderType.tpe.asInstanceOf[c.Type], silent = false) | ||
c.Expr( | ||
q"if (_root_.scala.scalajs.LinkingInfo.productionMode) null else $tpcls.asInstanceOf[_root_.slinky.core.StateReaderProvider]" | ||
) | ||
} | ||
|
||
implicit def get: StateReaderProvider = macro impl | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/scala-2/slinky/core/StateWriterProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package slinky.core | ||
|
||
import scala.scalajs.js | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.whitebox | ||
|
||
trait StateWriterProvider extends js.Object | ||
object StateWriterProvider { | ||
def impl(c: whitebox.Context): c.Expr[StateWriterProvider] = { | ||
import c.universe._ | ||
val compName = c.internal.enclosingOwner.owner.asClass | ||
val q"$_; val x: $typedReaderType = null" = c.typecheck( | ||
q"@_root_.scala.annotation.unchecked.uncheckedStable val comp: $compName = null; val x: _root_.slinky.readwrite.Writer[comp.State] = null" | ||
) // scalafix:ok | ||
val tpcls = c.inferImplicitValue(typedReaderType.tpe.asInstanceOf[c.Type], silent = false) | ||
c.Expr( | ||
q"if (_root_.scala.scalajs.LinkingInfo.productionMode) null else $tpcls.asInstanceOf[_root_.slinky.core.StateWriterProvider]" | ||
) | ||
} | ||
|
||
implicit def get: StateWriterProvider = macro impl | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package slinky.core | ||
|
||
abstract class ComponentWrapper(implicit sr: => StateReaderProvider, sw: => StateWriterProvider) | ||
extends BaseComponentWrapper(sr, sw) { | ||
override type Definition = DefinitionBase[Props, State, Snapshot] | ||
} |
Oops, something went wrong.