-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add sealed classes example to client code
The code changes in this commit add a new file `Sealed.scala` to the `examples/client/src/main/scala/samples` directory. This file contains an example of using sealed classes in Scala. It defines a sealed trait `Animal` and two case classes `Horse` and `Lama` that extend the `Animal` trait. It also includes a case class `Owner` that has a `name` and a `pet` field of type `Animal`. The commit also updates the `HelloWorld.scala` file to include the new `sealedClasses` sample component. Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
- Loading branch information
1 parent
eef47d6
commit 5e8e7ae
Showing
3 changed files
with
32 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package samples | ||
|
||
import dev.cheleb.scalamigen.{*, given} | ||
|
||
import com.raquo.laminar.api.L.* | ||
|
||
import com.raquo.airstream.state.Var | ||
|
||
sealed trait Animal | ||
case class Horse(name: String, age: Int) extends Animal | ||
case class Lama(name: String, age: Int, splitDistance: Int) extends Animal | ||
|
||
case class Owner(name: String, pet: Animal) | ||
|
||
val sealedClasses = Sample( | ||
"Sealed", { | ||
|
||
val eitherVar = Var(Owner("Agnes", Horse("Scala le chat", 6))) | ||
|
||
div( | ||
child <-- eitherVar.signal.map { item => | ||
div( | ||
s"$item" | ||
) | ||
}, | ||
eitherVar.asForm | ||
) | ||
} | ||
) |
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