CallbackTo

japgolly.scalajs.react.callback.CallbackTo
See theCallbackTo companion object
final class CallbackTo[+A](val trampoline: Trampoline[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.

Type parameters

A

The type of result produced when the callback is invoked.

Attributes

Since

0.10.0

Companion
object
Graph
Supertypes
class AnyVal
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def &&(b: CallbackTo[Boolean]): CallbackTo[Boolean]
Extension method from CallbackTo

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

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

Attributes

inline def *>[B](inline runNext: CallbackTo[B]): CallbackTo[B]

Alias for >>.

Alias for >>.

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

Attributes

def <*[B](next: CallbackTo[B]): CallbackTo[A]

Sequence actions, discarding the value of the second argument.

Sequence actions, discarding the value of the second argument.

Attributes

inline 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.

Attributes

def <<?[B](prev: Option[CallbackTo[B]]): CallbackTo[A]

Convenient version of << that accepts an Option

Convenient version of << that accepts an Option

Attributes

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

Alias for tap.

Alias for tap.

Attributes

def >>[B](runNext: CallbackTo[B]): CallbackTo[B]

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

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

Attributes

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

Alias for flatMap.

Alias for flatMap.

Attributes

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.

Attributes

inline def asCBO: CallbackOption[A]
Extension method from CallbackTo
inline def async: AsyncCallback[A]

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

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.

Attributes

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

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

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

Attributes

def attemptTry: CallbackTo[Try[A]]
inline def debounce(inline 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.

Attributes

inline def debounce(inline 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.

Attributes

inline def debounceMs(inline 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.

Attributes

inline def delay(inline startIn: FiniteDuration): AsyncCallback[A]

Run asynchronously after a delay of a given duration.

Run asynchronously after a delay of a given duration.

Attributes

inline def delay(inline startIn: Duration): AsyncCallback[A]

Run asynchronously after a delay of a given duration.

Run asynchronously after a delay of a given duration.

Attributes

inline def delayMs(inline startInMilliseconds: Double): AsyncCallback[A]

Run asynchronously after a startInMilliseconds ms delay.

Run asynchronously after a startInMilliseconds ms delay.

Attributes

Runs this computation in the background.

Runs this computation in the background.

Attributes

def distFn: A => CallbackTo[B]
Extension method from CallbackTo

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

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

Attributes

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.

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.

Attributes

inline def flatMap[B](f: A => CallbackTo[B]): CallbackTo[B]
inline def flatMap2[C](f: (A, B) => CallbackTo[C]): CallbackTo[C]
Extension method from CallbackTo
def flatTap[B](t: A => CallbackTo[B]): CallbackTo[A]
inline def flatten[B](using ev: A => CallbackTo[B]): CallbackTo[B]
def handleError[AA >: A](f: Throwable => CallbackTo[AA]): CallbackTo[AA]
inline def isEmpty_?: Boolean
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.

Attributes

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

Log the duration of this callback's execution.

Log the duration of this callback's execution.

Attributes

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

Log the duration of this callback's execution.

Log the duration of this callback's execution.

Value parameters

name

Prefix to appear the log output.

Attributes

Log the duration of this callback's execution.

Log the duration of this callback's execution.

Attributes

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

Logs the result of this callback as it completes.

Logs the result of this callback as it completes.

Attributes

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

Logs the result of this callback as it completes.

Logs the result of this callback as it completes.

Value parameters

name

Prefix to appear the log output.

Attributes

Logs the result of this callback as it completes.

Logs the result of this callback as it completes.

Attributes

inline def map[B](f: A => B)(using ev: MapGuard[B]): CallbackTo[Out]
def maybeHandleError[AA >: A](f: PartialFunction[Throwable, CallbackTo[AA]]): CallbackTo[AA]
def memo(): CallbackTo[A]

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

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

Attributes

inline def precedeWith(inline runFirst: Unit): CallbackTo[A]

Convenience-method to run additional code before this callback.

Convenience-method to run additional code before this callback.

Attributes

inline def rateLimit(inline 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.

Attributes

Returns

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

inline def rateLimit(inline 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.

Attributes

Returns

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

inline def rateLimit(inline window: Duration, inline 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.

Attributes

Returns

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

inline def rateLimit(inline window: FiniteDuration, inline 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.

Attributes

Returns

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

inline def rateLimitMs(windowMs: Long, 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.

Attributes

Returns

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

Extension method from CallbackTo

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

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

Attributes

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

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

Attributes

Since

2.0.0

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.

Attributes

inline def runNow(): A

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.

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.

Attributes

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

Schedule for repeated execution every interval.

Schedule for repeated execution every interval.

Attributes

def setInterval(interval: FiniteDuration): CallbackTo[SetIntervalResult]

Schedule for repeated execution every interval.

Schedule for repeated execution every interval.

Attributes

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

Schedule this callback for repeated execution every interval milliseconds.

Schedule this callback for repeated execution every interval milliseconds.

Value parameters

interval

duration in milliseconds between executions

Attributes

Returns

A means to cancel the interval.

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.

Attributes

Returns

A means to cancel the timeout.

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.

Attributes

Returns

A means to cancel the timeout.

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.

Value parameters

interval

duration in milliseconds to wait

Attributes

Returns

A means to cancel the timeout.

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

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

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

Attributes

inline def thenRun[B](inline runNext: B)(using ev: MapGuard[B]): CallbackTo[Out]

Convenience-method to run additional code after this callback.

Convenience-method to run additional code after this callback.

Attributes

def to[F[_]](implicit F: Sync[F]): F[A]
Extension method from CallbackTo
def toJsCallback: UndefOr[Function0[A]]
inline def toJsFn: Function0[A]
inline def toJsFn1: Function1[Any, A]
inline def toScalaFn: () => A
inline def unary_!: CallbackTo[Boolean]
Extension method from CallbackTo

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

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

Attributes

inline def underlyingRepr: Trampoline[A]

The underlying representation of this value-class

The underlying representation of this value-class

Attributes

inline def unless(inline cond: Boolean): CallbackTo[Option[A]]

Conditional execution of this callback. Reverse of when.

Conditional execution of this callback. Reverse of when.

Value parameters

cond

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

Attributes

Returns

Some result of the callback executed, else None.

inline def unless_(inline cond: Boolean): Callback

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

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

Value parameters

cond

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

Attributes

def void: Callback

Discard the value produced by this callback.

Discard the value produced by this callback.

Attributes

inline def voidExplicit[B](using inline 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).

Attributes

inline def when(inline cond: Boolean): CallbackTo[Option[A]]

Conditional execution of this callback.

Conditional execution of this callback.

Value parameters

cond

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

Attributes

Returns

Some result of the callback executed, else None.

inline def when_(inline cond: Boolean): Callback

Conditional execution of this callback. Discards the result.

Conditional execution of this callback. Discards the result.

Value parameters

cond

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

Attributes

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

Record the duration of this callback's execution.

Record the duration of this callback's execution.

Attributes

def withFilter(f: A => Boolean): CallbackTo[A]
def zip[B](cb: CallbackTo[B]): CallbackTo[(A, B)]
def zipWith[B, C](cb: CallbackTo[B])(f: (A, B) => C): CallbackTo[C]
inline def |>[B](inline f: A => B)(using ev: MapGuard[B]): CallbackTo[Out]

Alias for map.

Alias for map.

Attributes

def ||(b: CallbackTo[Boolean]): CallbackTo[Boolean]
Extension method from CallbackTo

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

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

Attributes

Deprecated methods

inline def !: CallbackTo[Boolean]
Extension method from CallbackTo

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

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

Attributes

Deprecated
true