Skip to content

Commit

Permalink
API: Remove extraNodes from InsertContext
Browse files Browse the repository at this point in the history
- It is not needed anymore, we look at the JsMap instead.
- Also includes some unrelated cleanups
  • Loading branch information
raquo committed Feb 27, 2024
1 parent afa1b71 commit 5a023c4
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/raquo/laminar/api/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ trait Implicits extends Implicits.LowPriorityImplicits with CompositeValueMapper
Setter(element => maybeSetter.foreach(_.apply(element)))
}

/** Combine aa Seq of [[Setter]]-s into a single [[Setter]] that applies them all. */
/** Combine a Seq of [[Setter]]-s into a single [[Setter]] that applies them all. */
implicit def seqToSetter[El <: ReactiveElement.Base](setters: collection.Seq[Setter[El]]): Setter[El] = {
Setter(element => setters.foreach(_.apply(element)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.raquo.laminar.inserters
import com.raquo.airstream.core.Observable
import com.raquo.laminar.modifiers.RenderableNode
import com.raquo.laminar.nodes.{ChildNode, ParentNode}
import org.scalajs.dom

import scala.scalajs.js

Expand Down Expand Up @@ -83,7 +82,7 @@ object ChildInserter {

ctx.extraNodesMap.clear()
ctx.extraNodesMap.set(newChildNode.ref, newChildNode)
ctx.extraNodes = newChildNode :: Nil
// ctx.extraNodes = ChildrenSeq.fromJsVector(JsVector(newChildNode))
ctx.extraNodeCount = 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object ChildTextInserter {
// of elements in between different inserters (otherwise Laminar would lose track of the reserved
// spot in such cases).
ctx.extraNodesMap.clear()
ctx.extraNodes = Nil
// ctx.extraNodes = ChildrenSeq.empty
ctx.extraNodeCount = 0
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object ChildrenInserter {
ctx.extraNodeCount,
hooks
)
ctx.extraNodes = newChildren
// ctx.extraNodes = newChildren
ctx.extraNodesMap = newChildrenMap
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/scala/com/raquo/laminar/inserters/InsertContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ import scala.scalajs.js
* context left by the previous inserter in onMountBind.
* @param extraNodeCount - Number of child nodes in addition to the sentinel node.
* Warning: can get out of sync with the real DOM!
* @param extraNodes - Ordered list of child nodes in addition to the sentinel node.
* Warning: can get out of sync with the real DOM!
* @param extraNodesMap - Map of child nodes, for more efficient search
* @param extraNodesMap - Map of child nodes in addition to the sentinel node,
* for more efficient search
* Warning: can get out of sync with the real DOM!
*/
final class InsertContext(
val parentNode: ReactiveElement.Base,
var sentinelNode: ChildNode.Base,
var strictMode: Boolean,
var extraNodeCount: Int, // This is separate from `extraNodesMap` for performance #TODO[Performance]: Check if this is still relevant with JsMap
var extraNodes: immutable.Seq[ChildNode.Base],
// var extraNodes: immutable.Seq[ChildNode.Base],
var extraNodesMap: JsMap[dom.Node, ChildNode.Base]
) {

Expand Down Expand Up @@ -107,7 +106,7 @@ final class InsertContext(
// Convert loose mode context values to strict mode context values
sentinelNode = newSentinelNode
extraNodeCount = 1
extraNodes = contentNode :: Nil
// extraNodes = ChildrenSeq.fromJsVector(JsVector(contentNode))
extraNodesMap.set(contentNode.ref, contentNode) // we initialized the map above
}
strictMode = true
Expand Down Expand Up @@ -182,7 +181,7 @@ object InsertContext {
sentinelNode = sentinelNode,
strictMode = strictMode,
extraNodeCount = 0,
extraNodes = Nil,
// extraNodes = ChildrenSeq.empty,
extraNodesMap = if (strictMode) new JsMap() else null
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/com/raquo/laminar/SyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ class SyntaxSpec extends UnitSpec {
)

el.amend(
onMountBind(_ => observable --> ((num: Int) => num * 5)),
onMountBind(_ => signal --> ((num: Int) => num * 5)),
onMountBind(_ => stream --> ((num: Int) => num * 5))
onMountBind(_ => observable --> ((num: Int) => noop(num * 5))), // #nc
onMountBind(_ => signal --> ((num: Int) => noop(num * 5))),
onMountBind(_ => stream --> ((num: Int) => noop(num * 5)))
)

el.amend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Button {

private val tag: HtmlTag[Ref] = htmlTag("mwc-button")

val id: HtmlProp[String] = idAttr
val id: HtmlProp[String, String] = idAttr

val label: HtmlAttr[String] = htmlAttr("label", StringAsIsCodec)
val raised: HtmlAttr[Boolean] = htmlAttr("raised", BooleanAsAttrPresenceCodec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ object LinearProgressBar {

private val tag: HtmlTag[Ref] = htmlTag("mwc-linear-progress")

val indeterminate: HtmlProp[Boolean] = htmlProp("indeterminate", BooleanAsIsCodec)
val reverse: HtmlProp[Boolean] = htmlProp("reverse", BooleanAsIsCodec)
val closed: HtmlProp[Boolean] = htmlProp("closed", BooleanAsIsCodec)
val progress: HtmlProp[Double] = htmlProp("progress", DoubleAsIsCodec)
val buffer: HtmlProp[Double] = htmlProp("buffer", DoubleAsIsCodec)
val indeterminate: HtmlProp[Boolean, Boolean] = htmlProp("indeterminate", BooleanAsIsCodec)
val reverse: HtmlProp[Boolean, Boolean] = htmlProp("reverse", BooleanAsIsCodec)
val closed: HtmlProp[Boolean, Boolean] = htmlProp("closed", BooleanAsIsCodec)
val progress: HtmlProp[Double, Double] = htmlProp("progress", DoubleAsIsCodec)
val buffer: HtmlProp[Double, Double] = htmlProp("buffer", DoubleAsIsCodec)

object styles {
val mdcThemePrimary: StyleProp[String] = styleProp("--mdc-theme-primary")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ object Slider {

private val tag: HtmlTag[Ref] = htmlTag("mwc-slider")

val pin: HtmlProp[Boolean] = htmlProp("pin", BooleanAsIsCodec)
val markers: HtmlProp[Boolean] = htmlProp("markers", BooleanAsIsCodec)
val value: HtmlProp[Double] = htmlProp("value", DoubleAsIsCodec)
val min: HtmlProp[Double] = htmlProp("min", DoubleAsIsCodec)
val max: HtmlProp[Double] = htmlProp("max", DoubleAsIsCodec)
val step: HtmlProp[Double] = htmlProp("step", DoubleAsIsCodec)
val pin: HtmlProp[Boolean, Boolean] = htmlProp("pin", BooleanAsIsCodec)
val markers: HtmlProp[Boolean, Boolean] = htmlProp("markers", BooleanAsIsCodec)
val value: HtmlProp[Double, Double] = htmlProp("value", DoubleAsIsCodec)
val min: HtmlProp[Double, Double] = htmlProp("min", DoubleAsIsCodec)
val max: HtmlProp[Double, Double] = htmlProp("max", DoubleAsIsCodec)
val step: HtmlProp[Double, Double] = htmlProp("step", DoubleAsIsCodec)


val onInput: EventProp[dom.Event] = eventProp("input")
Expand Down

0 comments on commit 5a023c4

Please sign in to comment.