Skip to content

Commit

Permalink
Fix: Avoid or delay instantiating some internal comment nodes until t…
Browse files Browse the repository at this point in the history
…hey are needed

Should be a tiny performance boost for `child.maybe <--` et al
  • Loading branch information
raquo committed Dec 12, 2024
1 parent 7a551c6 commit 84e08fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.raquo.laminar.nodes.{ChildNode, CommentNode}
object ChildOptionReceiver {

def <--(maybeChildSource: Source[Option[ChildNode.Base]]): DynamicInserter = {
val emptyNode = new CommentNode("")
lazy val emptyNode = new CommentNode("")
child <-- maybeChildSource.toObservable.map(_.getOrElse(emptyNode))
}

Expand All @@ -20,7 +20,7 @@ object ChildOptionReceiver {
)(implicit
renderable: RenderableNode[Component]
): DynamicInserter = {
val emptyNode = new CommentNode("")
lazy val emptyNode = new CommentNode("")
child <-- {
maybeChildSource
.toObservable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LockedChildReceiver(

/** If `includeSource` emits true, node will be added. Otherwise, it will be removed. */
def <--(includeSource: Source[Boolean]): DynamicInserter = {
val emptyNode = new CommentNode("")
lazy val emptyNode = new CommentNode("")
child <-- includeSource.toObservable.map(if (_) node else emptyNode)
}

Expand Down

0 comments on commit 84e08fb

Please sign in to comment.