Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

danielnixon/safer-dom

Repository files navigation

safer-dom

Build Status Maven Central

A scala-js-dom library that replaces nullable return types T (which the web APIs like to do everywhere) with Option[T].

Usage

  1. Add the dependency to your build:

libraryDependencies += "org.danielnixon" %%% "safer-dom" % "0.4.0"

  1. Import org.danielnixon.saferdom.implicits._.

  2. 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")