All Downloads are FREE. Search and download functionalities are using the official Maven repository.

japgolly.webapputil.browser.WindowPrompt.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC12
Show newest version
package japgolly.webapputil.browser

import japgolly.scalajs.react.{CallbackTo, Reusability}

/** Abstraction over `window.prompt`. */
trait WindowPrompt {
  def apply(message: String): CallbackTo[Option[String]]
  def apply(message: String, default: String): CallbackTo[Option[String]]
}

object WindowPrompt {

  val real: WindowPrompt =
    new WindowPrompt {
      override def apply(message: String): CallbackTo[Option[String]] =
        CallbackTo.prompt(message)

      override def apply(message: String, default: String): CallbackTo[Option[String]] =
        CallbackTo.prompt(message, default)
    }

  def const(answer: Option[String]): WindowPrompt =
    const(CallbackTo.pure(answer))

  def const(cb: CallbackTo[Option[String]]): WindowPrompt =
    new WindowPrompt {
      override def apply(message: String) = cb
      override def apply(message: String, default: String) = cb
    }

  implicit def reusability: Reusability[WindowPrompt] =
    Reusability.byRef
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy