-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: conditional syntax for child, children, and text receivers
- Loading branch information
Showing
12 changed files
with
442 additions
and
3 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
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
28 changes: 28 additions & 0 deletions
28
src/main/scala/com/raquo/laminar/receivers/LockedChildReceiver.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,28 @@ | ||
package com.raquo.laminar.receivers | ||
|
||
import com.raquo.airstream.core.Source | ||
import com.raquo.laminar.api.L.child | ||
import com.raquo.laminar.modifiers.Inserter | ||
import com.raquo.laminar.nodes.{ChildNode, CommentNode} | ||
|
||
class LockedChildReceiver( | ||
node: ChildNode.Base | ||
) { | ||
|
||
/** If `include` is true, the node will be added. Otherwise, an empty node will be added. */ | ||
@inline def apply(include: Boolean): ChildNode.Base = { | ||
this := include | ||
} | ||
|
||
/** If `include` is true, the node will be added. Otherwise, an empty node will be added. */ | ||
def :=(include: Boolean): ChildNode.Base = { | ||
if (include) node else new CommentNode("") | ||
} | ||
|
||
/** If `includeSource` emits true, node will be added. Otherwise, it will be removed. */ | ||
def <--(includeSource: Source[Boolean]): Inserter.Base = { | ||
val emptyNode = new CommentNode("") | ||
child <-- includeSource.toObservable.map(if (_) node else emptyNode) | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/scala/com/raquo/laminar/receivers/LockedChildTextReceiver.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,26 @@ | ||
package com.raquo.laminar.receivers | ||
|
||
import com.raquo.airstream.core.Source | ||
import com.raquo.laminar.api.L.child | ||
import com.raquo.laminar.modifiers.Inserter | ||
import com.raquo.laminar.nodes.{ChildNode, CommentNode, TextNode} | ||
|
||
class LockedChildTextReceiver( | ||
val text: String | ||
) { | ||
|
||
/** If `include` is true, the text will be added. Otherwise, an empty node will be added. */ | ||
@inline def apply(include: Boolean): ChildNode.Base = { | ||
this := include | ||
} | ||
|
||
/** If `include` is true, the text will be added. Otherwise, an empty node will be added. */ | ||
def :=(include: Boolean): ChildNode.Base = { | ||
if (include) new TextNode(text) else new CommentNode("") | ||
} | ||
|
||
/** If `includeSource` emits true, text will be added. Otherwise, it will be removed. */ | ||
def <--(includeSource: Source[Boolean]): Inserter.Base = { | ||
child.text <-- includeSource.toObservable.map(if (_) text else "") | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/scala/com/raquo/laminar/receivers/LockedChildrenReceiver.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,29 @@ | ||
package com.raquo.laminar.receivers | ||
|
||
import com.raquo.airstream.core.Source | ||
import com.raquo.laminar.api.L.children | ||
import com.raquo.laminar.modifiers.Inserter | ||
import com.raquo.laminar.nodes.ChildNode | ||
|
||
import scala.collection.immutable | ||
|
||
class LockedChildrenReceiver( | ||
val nodes: immutable.Seq[ChildNode.Base] | ||
) { | ||
|
||
/** If `include` is true, the nodes will be added. */ | ||
@inline def apply(include: Boolean): immutable.Seq[ChildNode.Base] = { | ||
this := include | ||
} | ||
|
||
/** If `include` is true, the nodes will be added. */ | ||
def :=(include: Boolean): immutable.Seq[ChildNode.Base] = { | ||
if (include) nodes else Nil | ||
} | ||
|
||
/** If `includeSource` emits true, node will be added. Otherwise, it will be removed. */ | ||
def <--(includeSource: Source[Boolean]): Inserter.Base = { | ||
children <-- includeSource.toObservable.map(if (_) nodes else Nil) | ||
} | ||
|
||
} |
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
Oops, something went wrong.