Packages

final class CallbackTo[+A] extends AnyVal

A function to be executed later, usually by scalajs-react in response to some kind of event.

The purpose of this class is to lift effects into the type system, and use the compiler to ensure safety around callbacks (without depending on an external library like Cats).

() => Unit is replaced by Callback. Similarly, ReactEvent => Unit is replaced by ReactEvent => Callback.

A

The type of result produced when the callback is invoked.

Self Type
CallbackTo[A]
Since

0.10.0

Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. CallbackTo
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##: Int
    Definition Classes
    Any
  3. def &&(b: CallbackTo[Boolean])(implicit ev: <:<[CallbackTo[A], CallbackTo[Boolean]]): CallbackTo[Boolean]

    Creates a new callback that returns true when both this and the given callback return true.

  4. def *>[B](runNext: CallbackTo[B]): CallbackTo[B]

    Alias for >>.

    Alias for >>.

    Where >> is often associated with Monads, *> is often associated with Applicatives.

    Annotations
    @inline()
  5. def <*[B](next: CallbackTo[B]): CallbackTo[A]

    Sequence actions, discarding the value of the second argument.

  6. def <<[B](runBefore: CallbackTo[B]): CallbackTo[A]

    Sequence a callback to run before this, discarding any value produced by it.

    Sequence a callback to run before this, discarding any value produced by it.

    Annotations
    @inline()
  7. def <<?[B](prev: Option[CallbackTo[B]]): CallbackTo[A]

    Convenient version of << that accepts an Option

  8. def <|(t: (A) => Any): CallbackTo[A]

    Alias for tap.

    Alias for tap.

    Annotations
    @inline()
  9. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  10. def >>[B](runNext: CallbackTo[B]): CallbackTo[B]

    Sequence a callback to run after this, discarding any value produced by this.

  11. def >>=[B](f: (A) => CallbackTo[B]): CallbackTo[B]

    Alias for flatMap.

    Alias for flatMap.

    Annotations
    @inline()
  12. def asAsyncCallback: AsyncCallback[A]

    Turns this into an AsyncCallback that runs whenever/wherever it's called; setTimeout isn't used.

    Turns this into an AsyncCallback that runs whenever/wherever it's called; setTimeout isn't used.

    In order words, this.toAsyncCallback.toCallback == this.

  13. def asCBO[B](implicit ev: <:<[CallbackTo[A], CallbackTo[Option[B]]]): CallbackOption[B]
  14. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  15. def async: AsyncCallback[A]

    Schedules this to run asynchronously (i.e.

    Schedules this to run asynchronously (i.e. uses a setTimeout).

    Exceptions will be handled by the AsyncCallback such that this.async.toCallback will never throw an exception.

  16. def attempt: CallbackTo[Either[Throwable, A]]

    Wraps this callback in a try-catch and returns either the result or the exception if one occurs.

  17. def attemptTry: CallbackTo[Try[A]]
  18. def debounce(delay: FiniteDuration): Callback

    Creates an debounce boundary over the underlying computation.

    Creates an debounce boundary over the underlying computation.

    Save the result of this as a val somewhere because it relies on internal state that must be reused.

  19. def debounce(delay: Duration): Callback

    Creates an debounce boundary over the underlying computation.

    Creates an debounce boundary over the underlying computation.

    Save the result of this as a val somewhere because it relies on internal state that must be reused.

  20. def debounceMs(delayMs: Long): Callback

    Creates an debounce boundary over the underlying computation.

    Creates an debounce boundary over the underlying computation.

    Save the result of this as a val somewhere because it relies on internal state that must be reused.

  21. def delay(startIn: Duration): AsyncCallback[A]

    Run asynchronously after a delay of a given duration.

  22. def delay(startIn: FiniteDuration): AsyncCallback[A]

    Run asynchronously after a delay of a given duration.

  23. def delayMs(startInMilliseconds: Double): AsyncCallback[A]

    Run asynchronously after a startInMilliseconds ms delay.

  24. def dispatch: Callback

    Runs this computation in the background.

  25. def distFn[B, C](implicit ev: <:<[CallbackTo[A], CallbackTo[(B) => C]]): (B) => CallbackTo[C]

    Function distribution.

    Function distribution. See CallbackTo.liftTraverse(f).id for the dual.

  26. def finallyRun[B](runFinally: CallbackTo[B]): CallbackTo[A]

    Wraps this callback in a try-finally block and runs the given callback in the finally clause, after the current callback completes, be it in error or success.

  27. def flatMap[B](f: (A) => CallbackTo[B]): CallbackTo[B]
  28. def flatMap2[X, Y, Z](f: (X, Y) => CallbackTo[Z])(implicit ev: <:<[A, (X, Y)]): CallbackTo[Z]
  29. def flatTap[B](t: (A) => CallbackTo[B]): CallbackTo[A]
  30. def flatten[B](implicit ev: (A) => CallbackTo[B]): CallbackTo[B]
  31. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  32. def handleError[AA >: A](f: (Throwable) => CallbackTo[AA]): CallbackTo[AA]
  33. def isEmpty_?: Boolean
  34. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  35. def logAround(message: Any, optionalParams: Any*): CallbackTo[A]

    Log to the console before this callback starts, and after it completes.

    Log to the console before this callback starts, and after it completes.

    Does not change the result.

  36. def logDuration: CallbackTo[A]

    Log the duration of this callback's execution.

  37. def logDuration(name: String): CallbackTo[A]

    Log the duration of this callback's execution.

    Log the duration of this callback's execution.

    name

    Prefix to appear the log output.

  38. def logDuration(fmt: (FiniteDuration) => String): CallbackTo[A]

    Log the duration of this callback's execution.

  39. def logResult: CallbackTo[A]

    Logs the result of this callback as it completes.

  40. def logResult(name: String): CallbackTo[A]

    Logs the result of this callback as it completes.

    Logs the result of this callback as it completes.

    name

    Prefix to appear the log output.

  41. def logResult(msg: (A) => String): CallbackTo[A]

    Logs the result of this callback as it completes.

  42. def map[B](f: (A) => B)(implicit ev: MapGuard[B]): CallbackTo[Out]
  43. def maybeHandleError[AA >: A](f: PartialFunction[Throwable, CallbackTo[AA]]): CallbackTo[AA]
  44. def memo(): CallbackTo[A]

    Return a version of this callback that will only execute once, and reuse the result for all other invocations.

  45. def precedeWith(runFirst: => Unit): CallbackTo[A]

    Convenience-method to run additional code before this callback.

  46. def rateLimit(window: FiniteDuration, maxPerWindow: Int): CallbackTo[Option[A]]

    Limits the number of invocations in a given amount of time.

    Limits the number of invocations in a given amount of time.

    returns

    Some if invocation was allowed, None if rejected/rate-limited

  47. def rateLimit(window: Duration, maxPerWindow: Int): CallbackTo[Option[A]]

    Limits the number of invocations in a given amount of time.

    Limits the number of invocations in a given amount of time.

    returns

    Some if invocation was allowed, None if rejected/rate-limited

  48. def rateLimit(window: FiniteDuration): CallbackTo[Option[A]]

    Limits the number of invocations in a given amount of time.

    Limits the number of invocations in a given amount of time.

    returns

    Some if invocation was allowed, None if rejected/rate-limited

  49. def rateLimit(window: Duration): CallbackTo[Option[A]]

    Limits the number of invocations in a given amount of time.

    Limits the number of invocations in a given amount of time.

    returns

    Some if invocation was allowed, None if rejected/rate-limited

  50. def rateLimitMs(windowMs: Long, maxPerWindow: Int = 1): CallbackTo[Option[A]]

    Limits the number of invocations in a given amount of time.

    Limits the number of invocations in a given amount of time.

    returns

    Some if invocation was allowed, None if rejected/rate-limited

  51. def requireCBO(implicit ev: <:<[CallbackTo[A], CallbackTo[Boolean]]): CallbackOption[Unit]

    Returns a CallbackOption that requires the boolean value therein to be true.

  52. def reset: Callback

    If this completes successfully, discard the result.

    If this completes successfully, discard the result. If any exception occurs, call printStackTrace and continue.

    Since

    2.0.0

  53. def ret[B](b: B): CallbackTo[B]

    Discard the callback's return value, return a given value instead.

    Discard the callback's return value, return a given value instead.

    ret, short for return.

  54. def runNow(): A

    Executes this callback, on the current thread, right now, blocking until complete.

    Executes this callback, on the current thread, right now, blocking until complete. Exceptions will not be thrown, not caught. Use CallbackTo#attempt to catch exceptions.

    Typically, callbacks are passed to scalajs-react and you're expected not to call this method yourself. Generally speaking, the only time you should call this method is in some other non-React code's async callback. Inside an AJAX callback is a common example. Even for those cases though, you can avoid calling this by getting direct access instead of callback-based access to your component; see the online WebSockets example: https://japgolly.github.io/scalajs-react/#examples/websockets

    While it's technically safe to call CallbackTo#runNow inside the body of another Callback, it's better to just use combinators like CallbackTo#flatMap or even a Scala for-comprehension.

    Annotations
    @inline()
  55. def setInterval(interval: FiniteDuration): CallbackTo[SetIntervalResult]

    Schedule for repeated execution every interval.

  56. def setInterval(interval: Duration): CallbackTo[SetIntervalResult]

    Schedule for repeated execution every interval.

  57. def setIntervalMs(interval: Double): CallbackTo[SetIntervalResult]

    Schedule this callback for repeated execution every interval milliseconds.

    Schedule this callback for repeated execution every interval milliseconds.

    interval

    duration in milliseconds between executions

    returns

    A means to cancel the interval.

  58. def setTimeout(interval: FiniteDuration): CallbackTo[SetTimeoutResult]

    Schedule this callback for execution in interval.

    Schedule this callback for execution in interval.

    Note: in most cases delay() is a better alternative.

    returns

    A means to cancel the timeout.

  59. def setTimeout(interval: Duration): CallbackTo[SetTimeoutResult]

    Schedule this callback for execution in interval.

    Schedule this callback for execution in interval.

    Note: in most cases delay() is a better alternative.

    returns

    A means to cancel the timeout.

  60. def setTimeoutMs(interval: Double): CallbackTo[SetTimeoutResult]

    Schedule this callback for execution in interval milliseconds.

    Schedule this callback for execution in interval milliseconds.

    Note: in most cases delayMs() is a better alternative.

    interval

    duration in milliseconds to wait

    returns

    A means to cancel the timeout.

  61. def tap(t: (A) => Any): CallbackTo[A]

    When the callback result becomes available, perform a given side-effect with it.

  62. def thenRun[B](runNext: => B)(implicit ev: MapGuard[B]): CallbackTo[Out]

    Convenience-method to run additional code after this callback.

  63. def toCBO: CallbackOption[A]
  64. def toJsCallback: UndefOr[Function0[A]]
  65. def toJsFn: Function0[A]
  66. def toJsFn1: Function1[Any, A]
  67. def toScalaFn: () => A
    Annotations
    @inline()
  68. def toString(): String
    Definition Classes
    Any
  69. def unary_!(implicit ev: <:<[CallbackTo[A], CallbackTo[Boolean]]): CallbackTo[Boolean]

    Negates the callback result (so long as it's boolean).

  70. def underlyingRepr: Trampoline[A]

    The underlying representation of this value-class

  71. def unless(cond: => Boolean): CallbackTo[Option[A]]

    Conditional execution of this callback.

    Conditional execution of this callback. Reverse of when().

    cond

    The condition required to be false for this callback to execute.

    returns

    Some result of the callback executed, else None.

  72. def unless_(cond: => Boolean): Callback

    Conditional execution of this callback.

    Conditional execution of this callback. Discards the result. Reverse of when_().

    cond

    The condition required to be false for the callback to execute.

  73. def void: Callback

    Discard the value produced by this callback.

  74. def voidExplicit[B](implicit ev: <:<[A, B]): Callback

    Discard the value produced by this callback.

    Discard the value produced by this callback.

    This method allows you to be explicit about the type you're discarding (which may change in future).

    Annotations
    @inline()
  75. def when(cond: => Boolean): CallbackTo[Option[A]]

    Conditional execution of this callback.

    Conditional execution of this callback.

    cond

    The condition required to be true for this callback to execute.

    returns

    Some result of the callback executed, else None.

  76. def when_(cond: => Boolean): Callback

    Conditional execution of this callback.

    Conditional execution of this callback. Discards the result.

    cond

    The condition required to be true for this callback to execute.

  77. def withDuration[B](f: (A, FiniteDuration) => CallbackTo[B]): CallbackTo[B]

    Record the duration of this callback's execution.

  78. def withFilter(f: (A) => Boolean): CallbackTo[A]
  79. def zip[B](cb: CallbackTo[B]): CallbackTo[(A, B)]
  80. def zipWith[B, C](cb: CallbackTo[B])(f: (A, B) => C): CallbackTo[C]
  81. def |>[B](f: (A) => B)(implicit ev: MapGuard[B]): CallbackTo[Out]

    Alias for map.

    Alias for map.

    Annotations
    @inline()
  82. def ||(b: CallbackTo[Boolean])(implicit ev: <:<[CallbackTo[A], CallbackTo[Boolean]]): CallbackTo[Boolean]

    Creates a new callback that returns true when either this or the given callback return true.

Deprecated Value Members

  1. def !(implicit ev: <:<[CallbackTo[A], CallbackTo[Boolean]]): CallbackTo[Boolean]

    Negates the callback result (so long as it's boolean).

    Negates the callback result (so long as it's boolean).

    Annotations
    @deprecated
    Deprecated

    (Since version 2.0.0) Use !cb instead of cb.!

Inherited from AnyVal

Inherited from Any

Ungrouped