safer-dom
A scala-js-dom library that replaces nullable return types T
(which the web APIs like to do everywhere) with Option[T]
.
Usage
- Add the dependency to your build:
libraryDependencies += "org.danielnixon" %%% "safer-dom" % "0.4.0"
-
Import
org.danielnixon.saferdom.implicits._
. -
Replace calls to nullable methods (e.g.
document.querySelector()
) with their safer alternatives (e.g.document.querySelectorOpt()
).
For example, this (which would have exploded with a TypeError
at runtime):
window.document.querySelector("nope").innerHTML = "foo"
can be now be written as:
import org.danielnixon.saferdom.implicits._
window.document.querySelectorOpt("nope").foreach(_.innerHTML = "foo")