Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: inline def #54

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.raquo.domtypes.generic.builders

/** Tag represents an Element builder */
class Tag[+Element](
@inline class Tag[+Element](
val name: String,
val void: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,52 @@ package object codecs {
object IntAsIsCodec extends AsIsCodec[Int]

object IntAsStringCodec extends Codec[Int, String] {
override def decode(domValue: String): Int = domValue.toInt // @TODO this can throw exception. How do we handle this?
override def encode(scalaValue: Int): String = scalaValue.toString
@inline override def decode(domValue: String): Int = domValue.toInt // @TODO this can throw exception. How do we handle this?
@inline override def encode(scalaValue: Int): String = scalaValue.toString
}

// Double Codecs

object DoubleAsIsCodec extends AsIsCodec[Double]

object DoubleAsStringCodec extends Codec[Double, String] {
override def decode(domValue: String): Double = domValue.toDouble// @TODO this can throw exception. How do we handle this?
override def encode(scalaValue: Double): String = scalaValue.toString
@inline override def decode(domValue: String): Double = domValue.toDouble// @TODO this can throw exception. How do we handle this?
@inline override def encode(scalaValue: Double): String = scalaValue.toString
}

// Boolean Codecs

object BooleanAsIsCodec extends AsIsCodec[Boolean]

object BooleanAsAttrPresenceCodec extends Codec[Boolean, String] {
override def decode(domValue: String): Boolean = domValue != null
override def encode(scalaValue: Boolean): String = if (scalaValue) "" else null
@inline override def decode(domValue: String): Boolean = domValue != null
@inline override def encode(scalaValue: Boolean): String = if (scalaValue) "" else null
}

object BooleanAsTrueFalseStringCodec extends Codec[Boolean, String] {
override def decode(domValue: String): Boolean = domValue == "true"
override def encode(scalaValue: Boolean): String = if (scalaValue) "true" else "false"
@inline override def decode(domValue: String): Boolean = domValue == "true"
@inline override def encode(scalaValue: Boolean): String = if (scalaValue) "true" else "false"
}

object BooleanAsYesNoStringCodec extends Codec[Boolean, String] {
override def decode(domValue: String): Boolean = domValue == "yes"
override def encode(scalaValue: Boolean): String = if (scalaValue) "yes" else "no"
@inline override def decode(domValue: String): Boolean = domValue == "yes"
@inline override def encode(scalaValue: Boolean): String = if (scalaValue) "yes" else "no"
}

object BooleanAsOnOffStringCodec extends Codec[Boolean, String] {
override def decode(domValue: String): Boolean = domValue == "on"
override def encode(scalaValue: Boolean): String = if (scalaValue) "on" else "off"
@inline override def decode(domValue: String): Boolean = domValue == "on"
@inline override def encode(scalaValue: Boolean): String = if (scalaValue) "on" else "off"
}

// Iterable Codecs

object IterableAsSpaceSeparatedStringCodec extends Codec[Iterable[String], String] { // use for e.g. className
override def decode(domValue: String): Iterable[String] = if (domValue == "") Nil else domValue.split(' ')
override def encode(scalaValue: Iterable[String]): String = scalaValue.mkString(" ")
@inline override def decode(domValue: String): Iterable[String] = if (domValue == "") Nil else domValue.split(' ')
@inline override def encode(scalaValue: Iterable[String]): String = scalaValue.mkString(" ")
}

object IterableAsCommaSeparatedStringCodec extends Codec[Iterable[String], String] { // use for lists of IDs
override def decode(domValue: String): Iterable[String] = if (domValue == "") Nil else domValue.split(',')
override def encode(scalaValue: Iterable[String]): String = scalaValue.mkString(",")
@inline override def decode(domValue: String): Iterable[String] = if (domValue == "") Nil else domValue.split(',')
@inline override def encode(scalaValue: Iterable[String]): String = scalaValue.mkString(",")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
/**
* Identifies the currently active descendant of a composite widget.
*/
lazy val activeDescendant: A[String] = stringHtmlAttr("aria-activedescendant")
@inline final def activeDescendant: A[String] = stringHtmlAttr("aria-activedescendant")

/**
* Indicates whether assistive technologies will present all, or only parts of, the
* changed region based on the change notifications defined by the aria-relevant
* attribute. See related [[relevant]].
*/
lazy val atomic: A[Boolean] = htmlAttr("aria-atomic", BooleanAsTrueFalseStringCodec)
@inline final def atomic: A[Boolean] = htmlAttr("aria-atomic", BooleanAsTrueFalseStringCodec)

/**
* Indicates whether user input completion suggestions are provided.
Expand All @@ -37,14 +37,14 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-autocomplete
*/
lazy val autoComplete: A[String] = stringHtmlAttr("aria-autocomplete")
@inline final def autoComplete: A[String] = stringHtmlAttr("aria-autocomplete")

/**
* Indicates whether an element, and its subtree, are currently being updated.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-busy
*/
lazy val busy: A[Boolean] = htmlAttr("aria-busy", BooleanAsTrueFalseStringCodec)
@inline final def busy: A[Boolean] = htmlAttr("aria-busy", BooleanAsTrueFalseStringCodec)

/**
* Indicates the current "checked" state of checkboxes, radio buttons, and other
Expand All @@ -55,31 +55,31 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-checked
*/
lazy val checked: A[String] = stringHtmlAttr("aria-checked")
@inline final def checked: A[String] = stringHtmlAttr("aria-checked")

/**
* Identifies the element (or elements) whose contents or presence are controlled
* by the current element. See related [[owns]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-controls
*/
lazy val controls: A[String] = stringHtmlAttr("aria-controls")
@inline final def controls: A[String] = stringHtmlAttr("aria-controls")

/**
* Identifies the element (or elements) that describes the object.
* See related [[labelledBy]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-describedby
*/
lazy val describedBy: A[String] = stringHtmlAttr("aria-describedby")
@inline final def describedBy: A[String] = stringHtmlAttr("aria-describedby")

/**
* Indicates that the element is perceivable but disabled, so it is not editable
* or otherwise operable. See related [[hidden]] and [[readOnly]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-disabled
*/
lazy val disabled: A[Boolean] = htmlAttr("aria-disabled", BooleanAsTrueFalseStringCodec)
@inline final def disabled: A[Boolean] = htmlAttr("aria-disabled", BooleanAsTrueFalseStringCodec)

/**
* Indicates what functions can be performed when the dragged object is released
Expand All @@ -93,15 +93,15 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-dropeffect
*/
lazy val dropEffect: A[String] = stringHtmlAttr("aria-dropeffect")
@inline final def dropEffect: A[String] = stringHtmlAttr("aria-dropeffect")

/**
* Indicates whether the element, or another grouping element it controls, is
* currently expanded or collapsed.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-expanded
*/
lazy val expanded: A[Boolean] = htmlAttr("aria-expanded", BooleanAsTrueFalseStringCodec)
@inline final def expanded: A[Boolean] = htmlAttr("aria-expanded", BooleanAsTrueFalseStringCodec)

/**
* Identifies the next element (or elements) in an alternate reading order of
Expand All @@ -110,21 +110,21 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-flowto
*/
lazy val flowTo: A[String] = stringHtmlAttr("aria-flowto")
@inline final def flowTo: A[String] = stringHtmlAttr("aria-flowto")

/**
* Indicates an element's "grabbed" state in a drag-and-drop operation.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-grabbed
*/
lazy val grabbed: A[Boolean] = htmlAttr("aria-grabbed", BooleanAsTrueFalseStringCodec)
@inline final def grabbed: A[Boolean] = htmlAttr("aria-grabbed", BooleanAsTrueFalseStringCodec)

/**
* Indicates that the element has a popup context menu or sub-level menu.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-haspopup
*/
lazy val hasPopup: A[Boolean] = htmlAttr("aria-haspopup", BooleanAsTrueFalseStringCodec)
@inline final def hasPopup: A[Boolean] = htmlAttr("aria-haspopup", BooleanAsTrueFalseStringCodec)

/**
* Indicates that the element and all of its descendants are not visible or
Expand All @@ -133,7 +133,7 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-hidden
*/
lazy val hidden: A[Boolean] = htmlAttr("aria-hidden", BooleanAsTrueFalseStringCodec)
@inline final def hidden: A[Boolean] = htmlAttr("aria-hidden", BooleanAsTrueFalseStringCodec)

/**
* Indicates the entered value does not conform to the format expected by the
Expand All @@ -143,30 +143,30 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-invalid
*/
lazy val invalid: A[String] = stringHtmlAttr("aria-invalid")
@inline final def invalid: A[String] = stringHtmlAttr("aria-invalid")

/**
* Defines a string value that labels the current element.
* See related [[labelledBy]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-label
*/
lazy val label: A[String] = stringHtmlAttr("aria-label")
@inline final def label: A[String] = stringHtmlAttr("aria-label")

/**
* Identifies the element (or elements) that labels the current element.
* See related [[label]] and [[describedBy]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby
*/
lazy val labelledBy: A[String] = stringHtmlAttr("aria-labelledby")
@inline final def labelledBy: A[String] = stringHtmlAttr("aria-labelledby")

/**
* Defines the hierarchical level of an element within a structure.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-level
*/
lazy val level: A[Int] = intHtmlAttr("aria-level")
@inline final def level: A[Int] = intHtmlAttr("aria-level")

/**
* Indicates that an element will be updated, and describes the types of updates the
Expand All @@ -176,21 +176,21 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-live
*/
lazy val live: A[String] = stringHtmlAttr("aria-live")
@inline final def live: A[String] = stringHtmlAttr("aria-live")

/**
* Indicates whether a text box accepts multiple lines of input or only a single line.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-multiline
*/
lazy val multiLine: A[Boolean] = htmlAttr("aria-multiline", BooleanAsTrueFalseStringCodec)
@inline final def multiLine: A[Boolean] = htmlAttr("aria-multiline", BooleanAsTrueFalseStringCodec)

/**
* Indicates that the user may select more than one item from the current selectable descendants.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-multiselectable
*/
lazy val multiSelectable: A[Boolean] = htmlAttr("aria-multiselectable", BooleanAsTrueFalseStringCodec)
@inline final def multiSelectable: A[Boolean] = htmlAttr("aria-multiselectable", BooleanAsTrueFalseStringCodec)

/**
* Indicates whether the element and orientation is horizontal or vertical.
Expand All @@ -199,7 +199,7 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-orientation
*/
lazy val orientation: A[String] = stringHtmlAttr("aria-orientation")
@inline final def orientation: A[String] = stringHtmlAttr("aria-orientation")

/**
* Identifies an element (or elements) in order to define a visual, functional, or
Expand All @@ -208,15 +208,15 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-owns
*/
lazy val owns: A[String] = stringHtmlAttr("aria-owns")
@inline final def owns: A[String] = stringHtmlAttr("aria-owns")

/**
* Defines an element's number or position in the current set of listitems or treeitems.
* Not required if all elements in the set are present in the DOM. See related [[setSize]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-posinset
*/
lazy val posInSet: A[Int] = intHtmlAttr("aria-posinset")
@inline final def posInSet: A[Int] = intHtmlAttr("aria-posinset")

/**
* Indicates the current "pressed" state of toggle buttons. See related [[checked]] and [[selected]].
Expand All @@ -226,14 +226,14 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-pressed
*/
lazy val pressed: A[String] = stringHtmlAttr("aria-pressed")
@inline final def pressed: A[String] = stringHtmlAttr("aria-pressed")

/**
* Indicates that the element is not editable, but is otherwise operable. See related [[disabled]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-readonly
*/
lazy val readOnly: A[Boolean] = htmlAttr("aria-readonly", BooleanAsTrueFalseStringCodec)
@inline final def readOnly: A[Boolean] = htmlAttr("aria-readonly", BooleanAsTrueFalseStringCodec)

/**
* Indicates what user agent change notifications (additions, removals, etc.)
Expand All @@ -243,22 +243,22 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-relevant
*/
lazy val relevant: A[String] = stringHtmlAttr("aria-relevant")
@inline final def relevant: A[String] = stringHtmlAttr("aria-relevant")

/**
* Indicates that user input is required on the element before a form may be submitted.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-required
*/
lazy val required: A[Boolean] = htmlAttr("aria-required", BooleanAsTrueFalseStringCodec)
@inline final def required: A[Boolean] = htmlAttr("aria-required", BooleanAsTrueFalseStringCodec)

/**
* Indicates the current "selected" state of various widgets.
* See related [[checked]] and [[pressed]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-selected
*/
lazy val selected: A[Boolean] = htmlAttr("aria-selected", BooleanAsTrueFalseStringCodec)
@inline final def selected: A[Boolean] = htmlAttr("aria-selected", BooleanAsTrueFalseStringCodec)

/**
* Defines the number of items in the current set of listitems or treeitems.
Expand All @@ -267,7 +267,7 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-setsize
*/
lazy val setSize: A[Int] = intHtmlAttr("aria-setsize")
@inline final def setSize: A[Int] = intHtmlAttr("aria-setsize")

/**
* Indicates if items in a table or grid are sorted in ascending or descending order.
Expand All @@ -276,33 +276,33 @@ trait AriaAttrs[A[_]] { this: HtmlAttrBuilder[A] =>
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-sort
*/
lazy val sort: A[String] = stringHtmlAttr("aria-sort")
@inline final def sort: A[String] = stringHtmlAttr("aria-sort")

/**
* Defines the maximum allowed value for a range widget.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-valuemax
*/
lazy val valueMax: A[Double] = doubleHtmlAttr("aria-valuemax")
@inline final def valueMax: A[Double] = doubleHtmlAttr("aria-valuemax")

/**
* Defines the minimum allowed value for a range widget.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-valuemin
*/
lazy val valueMin: A[Double] = doubleHtmlAttr("aria-valuemin")
@inline final def valueMin: A[Double] = doubleHtmlAttr("aria-valuemin")

/**
* Defines the current value for a range widget. See related [[valueText]].
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-valuenow
*/
lazy val valueNow: A[Double] = doubleHtmlAttr("aria-valuenow")
@inline final def valueNow: A[Double] = doubleHtmlAttr("aria-valuenow")

/**
* Defines the human readable text alternative of aria-valuenow for a range widget.
*
* https://www.w3.org/TR/wai-aria/states_and_properties#aria-valuetext
*/
lazy val valueText: A[String] = stringHtmlAttr("aria-valuetext")
@inline final def valueText: A[String] = stringHtmlAttr("aria-valuetext")
}
Loading