-
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 Validador support * Error bus * Refactor Sample layout
- Loading branch information
Showing
20 changed files
with
698 additions
and
264 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
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
7 changes: 7 additions & 0 deletions
7
examples/client/src/main/scala/facades/highlightjs/HljsLanguage.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,7 @@ | ||
package demo.facades.highlightjs | ||
|
||
import scala.scalajs.js | ||
|
||
/** Marker trait for all js Object that represents languages to be registered & Hljs | ||
*/ | ||
trait HljsLanguage extends js.Object |
16 changes: 16 additions & 0 deletions
16
examples/client/src/main/scala/facades/highlightjs/hljs.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,16 @@ | ||
package demo.facades.highlightjs | ||
|
||
import org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSImport | ||
|
||
@js.native | ||
@JSImport("highlight.js/lib/core", JSImport.Default) | ||
object hljs extends js.Object { | ||
|
||
def highlightElement(element: dom.HTMLElement): Unit = js.native | ||
|
||
def registerLanguage(name: String, language: HljsLanguage): Unit = js.native | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
examples/client/src/main/scala/facades/highlightjs/hljsScala.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,8 @@ | ||
package demo.facades.highlightjs | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSImport | ||
|
||
@js.native | ||
@JSImport("highlight.js/lib/languages/scala", JSImport.Default) | ||
object hljsScala extends HljsLanguage |
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
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ val person = { | |
pet: Option[Pet], | ||
email: Option[String], | ||
age: BigInt, | ||
size: Double | ||
size: Double :| Positive | ||
) | ||
case class Pet( | ||
name: String, | ||
|
@@ -49,15 +49,71 @@ val person = { | |
) | ||
|
||
val personVar = Var(vlad) | ||
|
||
val errorBus = personVar.errorBus | ||
|
||
Sample( | ||
"Person", | ||
div( | ||
child <-- personVar.signal.map { item => | ||
div( | ||
s"$item" | ||
) | ||
}, | ||
personVar.asForm | ||
) | ||
personVar.asForm(errorBus), | ||
div( | ||
child <-- errorBus.watch | ||
.map { errors => | ||
div( | ||
errors.collect { | ||
case (field, ValidationStatus.Invalid(message, true)) => | ||
div( | ||
s"$field: $message" | ||
) | ||
}.toSeq | ||
) | ||
} | ||
) | ||
), | ||
div(child <-- personVar.signal.map { item => | ||
div( | ||
s"$item" | ||
) | ||
}), | ||
"""| | ||
| @NoPanel | ||
| case class Person( | ||
| @FieldName("First Name") | ||
| name: String, | ||
| password: Password, | ||
| birthDate: LocalDate, | ||
| fav: Pet, | ||
| pet: Option[Pet], | ||
| email: Option[String], | ||
| age: BigInt, | ||
| size: Double :| Positive | ||
| ) | ||
| case class Pet( | ||
| name: String, | ||
| age: BigInt, | ||
| House: House, | ||
| size: Double :| Positive | ||
| ) | ||
| | ||
| case class House(capacity: Int) | ||
| | ||
| // Provide default for optional | ||
| given Defaultable[Pet] with | ||
| def default = Pet("No pet", 0, House(0), 1) | ||
| | ||
| // Instance your model | ||
| val vlad = | ||
| Person( | ||
| "", | ||
| Password("not a password"), | ||
| LocalDate.of(1431, 11, 8), | ||
| Pet("Batman", 666, House(2), 169), | ||
| Some(Pet("Wolfy", 12, House(1), 42)), | ||
| Some("[email protected]"), | ||
| 48, | ||
| 1.85 | ||
| ) | ||
| | ||
|""".stripMargin | ||
) | ||
} |
Oops, something went wrong.