Skip to content

Commit

Permalink
Merge pull request #739 from japgolly/topic/elidableVdom
Browse files Browse the repository at this point in the history
Add VdomAttr.elidable
  • Loading branch information
japgolly authored Jun 22, 2020
2 parents 38cb838 + 226a757 commit a007b99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/test-elision
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ case $# in
COMP_NAMES_ARE_ELIDABLE
DEVONLY
ELIDABLE_AUTO_COMPONENT_NAME
ELIDABLE_VDOM_ATTR
REUSABILITY_OVERRIDE_TEST
)
for t in "${terms[@]}"; do
Expand Down
12 changes: 11 additions & 1 deletion core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package japgolly.scalajs.react.vdom

import org.scalajs.dom
import scala.annotation.{implicitNotFound, nowarn}
import scala.annotation.{elidable, implicitNotFound, nowarn}
import scala.scalajs.LinkingInfo.developmentMode
import scala.scalajs.js
import japgolly.scalajs.react.internal.OptionLike
Expand Down Expand Up @@ -52,6 +52,16 @@ object Attr {
else
Dud

def elidable[A](name: => String): Attr[A] = {
@elidable(scala.annotation.elidable.FINEST)
def attempt: Attr[A] = new Generic(name)
val x = attempt
if (x eq null)
Dud
else
x
}

class Generic[-U](attrName: String) extends Attr[U](attrName) {
override def :=[A](a: A)(implicit t: ValueType[A, U]): TagMod =
t(attrName, a)
Expand Down
1 change: 1 addition & 0 deletions doc/changelog/1.7.2.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 1.7.2

* Fix: no longer generate warnings when `-Wunused:nowarn` is enabled
* Add `VdomAttr.elidable` which allows you to elide VDOM attributes with `scalacOptions`
4 changes: 4 additions & 0 deletions test/src/test/scala/japgolly/scalajs/react/ElisionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ object ElisionTest extends TestSuite {
.build
}

private val attr =
VdomAttr.elidable("data-ELIDABLE_VDOM_ATTR")

override def tests = Tests {
"normal" - s"[${Normal.raw.displayName}]"
"static" - s"[${Static.raw.displayName}]"
"attr" - ReactDOMServer.renderToStaticMarkup(<.div(attr := 1))

"reusabilityOverride" - {
ScalaJsReactConfig.DevOnly.overrideReusability(reusabilityOverride)
Expand Down

0 comments on commit a007b99

Please sign in to comment.