Skip to content

Commit

Permalink
New: nodeSeq, modSeq
Browse files Browse the repository at this point in the history
  • Loading branch information
raquo committed Dec 4, 2023
1 parent 0303dca commit 11c58e3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/scala/com/raquo/laminar/api/Laminar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ trait Laminar
new DetachedRoot(rootNode, activateNow)
}

/**
* Get a Seq of modifiers. You could just use Seq(...), but this helper
* has better type inference in some cases.
*/
def modSeq[El <: Element](mods: Modifier[El]*): Seq[Modifier[El]] = mods

/**
* Get a Seq of nodes. You could just use Seq(...), but this helper
* has better type inference in some cases.
*/
def nodeSeq[El <: Node](nodes: Node*): Seq[Node] = nodes

/** A universal Modifier that does nothing */
val emptyMod: Modifier.Base = Modifier.empty

Expand Down
33 changes: 33 additions & 0 deletions src/test/scala/com/raquo/laminar/basic/ModSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,37 @@ class ModSpec extends UnitSpec {
))
}

it("nodeSeq type inference") {

val nodes = nodeSeq("text", span("element"))

val el = div(
nodes
)

mount(el)

expectNode(
div.of("text", span.of("element"))
)
}

it("modSeq type inference") {

val mods = modSeq(title("world"), "text", span("element"))

val el = div(
"hello",
mods
)

mount(el)

expectNode(
div.of("hello", title is "world", "text", span.of("element"))
)
}



}

0 comments on commit 11c58e3

Please sign in to comment.